【发布时间】:2023-04-01 18:44:01
【问题描述】:
我正在开发的 iPhone 应用程序中遇到一个奇怪的问题。我希望我的应用支持ONLY纵向模式,但由于某种原因我不能做到(设备和模拟器)。
为了只支持纵向模式,我做了如下操作:
- 在 Xcode 的 TARGET 摘要部分,我只选择了纵向。
- 我所有的 ViewController 都实现了
shouldAutorotateToInterfaceOrientation
但正如我所说,它不起作用,奇怪的结果是应用支持所有方向(纵向、倒置、横向左侧、横向右侧)。
有任何想法吗?
这是我如何实现shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"Checking orientation %d", interfaceOrientation);
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
我刚刚注意到,当我转动手机时,我收到了这样一条消息:
“两阶段旋转动画已弃用。此应用程序应 使用更流畅的单阶段动画。”
什么意思?
【问题讨论】:
-
试试我的答案。也许会有所帮助。
-
尝试将
NSLog(@"Checking orientation %d", interfaceOrientation);添加到您的shouldAutorotateToInterfaceOrientation方法中。当您旋转模拟器或您的设备时,是否会调用它们中的任何一个? -
感谢您的帮助,是的,日志打印“检查方向 1”。但我注意到了其他问题,请检查我更新的问题
-
@Eyal:额外的控制台消息可能意味着您的代码实现了旧的和已弃用的didAnimateFirstHalfOfRotationToInterfaceOrientation:,以及类似的 willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: 和 willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:。你也许可以不用这些方法。
-
@Eyal: interfaceOrientation of 1 是
UIInterfaceOrientationPortrait,这是你所期望的。如果当您旋转到横向时确实发生了这种情况,这比以往任何时候都更奇怪:设备返回 YES 因为它认为它正在旋转到纵向。可以发一个完整的shouldAutorotateToInterfaceOrientation方法吗?
标签: iphone objective-c xcode autorotate device-orientation