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