我正在使用 Worklight Studio 6.2 for iOS 开发一个混合应用程序。应用程序应强制横向。在 iOS 7 中,当我调用本机页面时,即使我已将视图控制器设置为横向,方向也默认为纵向。 iOS 8 的方向正确。
我尝试使用以下代码将本机页面设置为横向,但它不起作用:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
任何帮助,将不胜感激。
Update:我们还修复了使用时出现的问题WL.NativePage.show
.
您需要打开 PMR 才能收到包含此修复程序的版本。
奇怪的是,它在 iOS 7 中不起作用,但在 iOS 8 中起作用。如果你愿意,你可以打开 PMR让 Worklight 开发团队进行调查。
也就是说,使用时方向确实可以正确工作SendAction
API,从 Worklight 6.2 开始可用。
发送操作 API基本上允许您向本机端发送“命令”(一个操作),通过此操作您可以做任何您想做的事情。例如,打开一个你自己的View Controller,你将完全控制它,这比什么都好得多WL.NativePage.show
允许你。
下面的例子是基于NativePagesInHyridApp 示例项目来自入门页面.
-
在 common\js\main.js 中,您可以在需要时发送一个操作:
function openNativePage(){
...
...
WL.App.sendActionToNative("openViewController");
}
-
在 NativePagesInHybridApp.h 中,添加WLActionReceiver
接口协议,即:
@interface MyViewController : MyViewController <WLInitWebFrameworkDelegate, WLActionReceiver> {
}
-
在 NativePagesInHybridApp.m 中,添加实现:
@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];
}
...
...
现在,当您启动应用程序并单击按钮时,生成的视图控制器将显示 - 也以横向方式显示。
在上面的示例中,视图控制器是用代码实现的,但您可以使用 XIB 或一个来创建自己的视图控制器在故事板中创建并调用它...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)