[英]Is it possible to change orientation with a button event but disable auto rotate?
我使用下面的代码来更改视图控制器的方向:
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
它可以迫使方向变为横向,但是我不能通过禁用自动旋转来使其工作:
-(BOOL)shouldAutorotate {
return NO;
}
是否可以通过按钮事件更改方向但禁用自动旋转?
声明布尔变量检查,然后根据该值可以启用或禁用Orientaion。
- (IBAction)someButton:(id)sender {
[self changeOrientation];
}
-(void)changeOrientation
{
check = true;
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
}
-(BOOL)shouldAutorotate {
if (check) {
return YES;
check = false;
}
return NO;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.