2015-10-13 106 views
1

我努力修改設備方向。我發現這個cordova插件https://github.com/gbenvenuti/cordova-plugin-screen-orientation,它與cordova應用程序一起工作,但不幸的是,它不能使用IBM MobileFirst Platform Foundation 7.0(+ Angular,Ionic)。無法鎖定和解鎖屏幕方向

我打開設備的方向在Xcode - >常規: xcode my project general

我也試着做小搓到屏幕方向科爾多瓦根據本https://forums.developer.apple.com/thread/6165插件,但它仍然沒有工作

這是接口它看起來YoikScreenOrientation.h

@interface ForcedViewController : UIViewController 

@property (strong, nonatomic) NSString *calledWith; 

@end 

和YoikScreenOrientation.m

@implementation ForcedViewController 

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
    - (NSUInteger)supportedInterfaceOrientations { 
     NSLog(@"lockViewController to ALL Portrait < 9"); 
     return UIInterfaceOrientationMaskPortrait; 

    } 
#else 
    -(UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
     NSLog(@"lockViewController to ALL Portrait > 9"); 
     return UIInterfaceOrientationPortrait; 
    } 
#endif 

@end 

我可以在日誌中看到它通過了supportedInterfaceOrientations方法,但它不會將屏幕方向鎖定爲縱向。有沒有我錯過的配置來鎖定或解鎖設備方向?

+0

1)最終目標是什麼?您是否嘗試以編程方式完成鎖定和解鎖,而不是常規選項中的設備方向選項? 2)Angular和Ionic與這個問題有什麼關係? 3)您是在物理設備還是在iOS模擬器中測試? –

+0

1)目標是將屏幕方向鎖定在一個頁面中,然後再次解鎖,我添加了常規選項未鎖定的圖像,指出設備方向已解鎖。 2)沒有什麼只是它用來構建應用程序的框架,3)是的,我在模擬器和真實設備上都進行了測試,這是同樣的行爲。 – Jan

回答

1

絕對沒問題科爾多瓦插件屏幕方向在這種情況下並沒有幫助,所以我最終創建了我的插件,使用此示例http://swiftiostutorials.com/ios-orientations-landscape-orientation-one-view-controller/並且工作,改變方向的關鍵是在方向改變之前調用的這個函數,這樣,我可以覆蓋定向橫向或縱向模式, appdelegate.m

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
    { 
     if ([LANSCAPE_MODE isEqualToString:orientationMode]){ 
      if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
       return UIInterfaceOrientationMaskPortraitUpsideDown; 
      else 
       return UIInterfaceOrientationMaskPortrait; 

     } 
     else{ 
      return UIInterfaceOrientationMaskAll; 
     } 

    } 

如果我嘗試使用supportedInterfaceOrientations方法來覆蓋它崩潰,如果不支持的方向,此鏈接解釋了崩潰 https://devforums.apple.com/message/731764#731764

+0

任何改變你可以給你更多關於你自己的插件的信息?我正在努力解決同樣的問題。 –