【问题标题】:Unable to lock and unlock screen orientation无法锁定和解锁屏幕方向
【发布时间】:2015-10-15 08:32:52
【问题描述】:

我正在努力修改设备方向。我找到了这个 cordova 插件 https://github.com/gbenvenuti/cordova-plugin-screen-orientation,它可以与 cordova 应用程序一起使用,但不幸的是无法使用 IBM MobileFirst Platform Foundation 7.0(+Angular,Ionic)。

我在 Xcode 中解锁了设备方向 -> 常规:

我还尝试根据https://forums.developer.apple.com/thread/6165 对屏幕方向 Cordova 插件进行小改动,但它仍然无法正常工作

这是看起来像 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 方法,但它没有将屏幕方向锁定为纵向。为了锁定或解锁设备方向,我是否遗漏了任何配置?

【问题讨论】:

  • 1) 最终目标是什么?您是否尝试以编程方式完成锁定和解锁,而不是“常规”选项中的“设备方向”选项? 2) Angular 和 Ionic 与这个问题有什么关系? 3) 您是在物理设备中还是在 iOS 模拟器中进行测试?
  • 1)目标是将屏幕方向锁定在一页然后再次解锁,我添加了常规选项解锁的图像以指出设备方向已解锁。 2) 没什么,只是我用来构建应用程序的框架,3) 是的,我在模拟器和真实设备上都进行了测试,并且行为相同。

标签: ios objective-c ibm-mobilefirst device-orientation


【解决方案1】:

在这种情况下,Cordova 插件屏幕方向肯定没有帮助,所以我最终使用这个例子创建了我的插件 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

【讨论】:

  • 您可以提供有关您自己制作的插件的更多信息吗?我正在努力解决同样的问题。
猜你喜欢
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
  • 2016-05-28
  • 1970-01-01
  • 1970-01-01
  • 2014-01-13
  • 2011-02-28
  • 2022-07-05
相关资源
最近更新 更多