如何在单击按钮时更改 iPhone 的方向?
我一直在搜索大量帖子,试图找到一种手动更改视图方向的方法。然而,我似乎找不到一个不过时的明确答案。请问有人可以建议根据用户按下按钮时切换方向的最佳方法吗?
即我需要一些帮助来填补空白......
- (IBAction)buttonPressed:(id)sender
{
// Switch the orientation to ...
}
I've been searching through lots of posts trying to find a way to change the orientation of the view manually. However I can't seem to find a definitive answer that's not outdated. Please can someone suggest the best way to switch the orientation based on when a user presses a button?
I.e. I need some help filling in the gap...
- (IBAction)buttonPressed:(id)sender
{
// Switch the orientation to ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
苹果的指导方针不允许这样做。有一些技巧可以做到这一点,但使用它并不是一个好主意。
您的应用程序将在真实设备中运行,并且没有任何代码可以物理地转动手机。设备方向受到现实世界的约束,您不能强迫用户转动手机。
The Apple guideline doesn't allow that. There's some hack to do that but it's not a good idea to use it.
Your app will run in a real device and there isn't any piece of code that can physically turn the phone. Device orientation is constraint by real world constraint, you can't force your user to turn his phone.
将方向更改为横向或纵向。
您可能还必须应用转换才能完成更改:
Change the orientation to Landscape or Portrait.
You might have to also apply a transformation to complete the change: