ios - 无法锁定和解锁屏幕方向

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

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

我在 Xcode -> general 中解锁了设备方向: xcode my project general

我还尝试根据此 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 方法传递,但它没有将屏幕方向锁定为纵向。为了锁定或解锁设备方向,我是否错过了任何配置?

最佳答案

当然 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

关于ios - 无法锁定和解锁屏幕方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33108715/

相关文章:

ios - 如何编写简单的单元测试来测试 JSON 的解析?

iphone - 在 AVAudioPlayer 播放之前做一些事情

ios - 是否可以在 JSON 数据中搜索特定键?

android - x86_64 模拟器上的 JSONStore Android 应用程序

ssl - Worklight Development SSL 问题(无法找到证书链)

ibm-mobilefirst - IBM MobileFirst Java Adapter (Hybrid Application) 下载大文件

ios - 在已获得焦点的模态 VC 中显示 UISearchController

ios - 如何实现 initWithCString :(const char *)nullTerminatedCString ? 为什么大多数人使用 allocWithZone 而不是 alloc?

ios - 设置相机闪光灯在iOS 10中不起作用

iphone - 确保可拖动的 ImageView 保持在框架的边界内