【发布时间】:2023-03-19 20:25:02
【问题描述】:
我想允许应该根据目标方向旋转
[[UIDevice currentDevice] orientation]
然而,上面的代码在 shouldRotate 中使用时保持当前(旧)方向,而不是目标方向
- (BOOL) shouldAutorotate {
return YES;
}
【问题讨论】:
我想允许应该根据目标方向旋转
[[UIDevice currentDevice] orientation]
然而,上面的代码在 shouldRotate 中使用时保持当前(旧)方向,而不是目标方向
- (BOOL) shouldAutorotate {
return YES;
}
【问题讨论】:
好的,我想通了。始终在 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
}
【讨论】:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
这种方法应该可以解决问题。 toInterfaceOrientation 保存目标方向。
【讨论】:
除了返回yes之外
-(BOOL)shouldAutorotate
{
return YES;
}
你必须执行
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
可用的不同面具是:
UIInterfaceOrientationMaskPortrait
UIInterfaceOrientationMaskLandscapeLeft
UIInterfaceOrientationMaskLandscapeRight
UIInterfaceOrientationMaskPortraitUpsideDown
UIInterfaceOrientationMaskLandscape
UIInterfaceOrientationMaskAll
UIInterfaceOrientationMaskAllButUpsideDown
您可能还想看:
【讨论】: