问题描述
我正在使用Worklight Studio 6.2 for iOS开发混合应用程式。应用程序应该被强制为横向。在iOS 7中,当我调用本地页面时,方向默认为纵向,即使我已将视图控制器设置为横向。
I'm developing a hybrid app using Worklight Studio 6.2 for iOS. The application should be forced to landscape orientation. In iOS 7, when I call a native page, the orientation defaults to portrait even though I have set the view controller to landscape. The orientation works correctly for iOS 8.
我尝试使用以下代码将原生页面设置为横向,但它不工作:
I tried to set the native page to landscape using the following code but it's not working:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
任何帮助将不胜感激。
推荐答案
更新:我们还修复了使用 WL.NativePage.show
。
您需要打开PMR才能收到含有此修复的版本。
Update: We also have a fix for the issue when using WL.NativePage.show
.
You will need to open a PMR in order to receive a version with this fix.
很奇怪,它不工作在iOS 7,但在iOS 8中。如果你想要你可以让Worklight开发团队对它进行查看。
It is strange that it's not working in iOS 7 but does in iOS 8. If you want you can open a PMR to have the Worklight development team look into it.
也就是说, SendAction
API(可从Worklight 6.2开始使用)。
基本上允许您发送一个命令 - 一个动作,本机端,通过这个动作,你可以做任何你想要的。例如,打开你自己的View Controller,你将完全控制它,这比 WL.NativePage.show
允许你更好。
That said, the orientation does work correctly when using the SendAction
API, available starting Worklight 6.2.
The SendAction API basically allows you to send a 'command' - an action, to the native side and with this action you can do whatever you want. For example, open a View Controller of your own that you will have full control over it, which is much better than what WL.NativePage.show
allows you.
以下示例基于 >入门页面。
The below example is based on the NativePagesInHyridApp sample project from the Getting Started page.
-
在common \js\main.js中, :
In common\js\main.js you send an action where required:
function openNativePage(){
...
...
WL.App.sendActionToNative("openViewController");
}
在NativePagesInHybridApp.h中, WLActionReceiver 协议到接口,即:
@interface MyViewController : MyViewController <WLInitWebFrameworkDelegate, WLActionReceiver> {
}
在NativePagesInHybridApp.m中, :
In NativePagesInHybridApp.m, add the implementation:
@implementation MyAppDelegate
-(void)onActionReceived:(NSString *)action withData:(NSDictionary*) data{
NSLog(@"onActionReceived :: %@", action);
[self performSelectorOnMainThread:@selector(addViewController) withObject:nil waitUntilDone:YES];
}
-(void)addViewController{
HelloNative *helloNativeViewController = [[HelloNative alloc] init];
[self.window.rootViewController addChildViewController:helloNativeViewController];
[self.window.rootViewController.view addSubview:helloNativeViewController.view];
}
...
...
现在,当您启动应用程序并单击按钮时,将会显示生成的视图控制器 - 在横向。
Now, when you launch the app and click the button, the generated view controller will be displayed - in landscape as well.
在上面的示例中,视图控制器是以代码实现的,但您可以使用XIB或一个中创建并调用它...
In the above example, a view controller is implemented in code, but you could create your own with a XIB or one created in Storyboard and call it up...
这篇关于Worklight 6.2和iOS7中的本机页面的定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!