我想根据目标方向允许旋转
[[UIDevice currentDevice] orientation]
然而,上面的代码在shouldRotate中使用时保持当前(旧)方向,而不是目标方向
- (BOOL) shouldAutorotate {
return YES;
}
答案 0 :(得分:0)
好吧我明白了。始终在shouldAutorotate中返回YES,然后执行以下操作:
- (NSUInteger)supportedInterfaceOrientations
{
if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
// Allow if you can
} else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
// Allow if you can
}
// so on
}
答案 1 :(得分:0)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
这种方法可以帮到你。 toInterfaceOrientation保持目标方向。
答案 2 :(得分:-1)
除了返回
之外-(BOOL)shouldAutorotate
{
return YES;
}
你必须实施
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
可用的不同面具是:
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
您可能也希望看到: