设置横屏没有生效:[[UIDevice currentDevice] setValue:value forKey:@"orientation"]

设置横屏(oc)代码:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

问题:横屏不生效!!!
原因:General中设置了竖屏模式,Device Orientation:Portrait
解决方法:需要在appdelegate设置
oc:
-- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
swift:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.allButUpsideDown;
}

猜你喜欢

转载自blog.csdn.net/weixin_33912638/article/details/87230725