2014-10-29 54 views
2

我正在開發一個使用Worklight Studio 6.2 for iOS的混合應用程序。應用程序應該被迫橫向定位。在iOS 7中,當我調用本機頁面時,即使已將視圖控制器設置爲橫向,方向仍默認爲縱向。取向工作正常的iOS 8Worklight 6.2和iOS7中原生頁面的方向問題

我嘗試使用下面的代碼來設置本機頁面的風景,但它不工作:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
return UIInterfaceOrientationMaskLandscape; 
} 

任何幫助,將不勝感激。

回答

0

更新:在使用WL.NativePage.show時,我們也對此問題進行了修復。
您需要打開PMR才能收到帶有此修補程序的版本。


如果你願意,你可以open a PMR有工作燈的開發團隊考慮它奇怪的是,它不是在iOS的7個工作,但確實在iOS的8。

也就是說,在使用SendAction API(可用於啓動Worklight 6.2)時,方向確實可以正常工作。
The SendAction API基本上可以讓你發送一個'命令' - 一個動作給本地人,並且通過這個動作你可以做任何你想做的事情。例如,打開一個您自己的視圖控制器,您將完全控制它,這比WL.NativePage.show允許您更好。

以下示例基於Getting Started pageNativePagesInHyridApp sample project

  1. 在共同\ JS \ main.js您發送如有需要一個動作:

    function openNativePage(){ 
        ... 
        ... 
        WL.App.sendActionToNative("openViewController"); 
    } 
    
  2. 在NativePagesInHybridApp.h中,WLActionReceiver協議添加到界面,即:

    @interface MyViewController : MyViewController <WLInitWebFrameworkDelegate, WLActionReceiver> { 
    
    } 
    
  3. 在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]; 
    } 
    
    ... 
    ... 
    

現在,當您啓動應用程序並單擊按鈕時,生成的視圖控制器也將顯示在橫向上。

在上面的例子中,視圖控制器在代碼中實現,但你可以創建自己的有廈門國際銀行或一個created in Storyboard並調用它...

+0

謝謝你的解決方法和修復。 – adriank 2014-10-31 03:27:24