无法锁定和解锁屏幕方向

问题描述:

我努力修改设备方向。我发现这个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

绝对没问题科尔多瓦插件屏幕方向在这种情况下并没有帮助,所以我最终创建了我的插件,使用此示例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

任何改变你可以给你更多关于你自己的插件的信息?我正在努力解决同样的问题。 –