如何在单击按钮时更改 iPhone 的方向?

发布于 2024-12-21 01:02:39 字数 216 浏览 3 评论 0原文

我一直在搜索大量帖子,试图找到一种手动更改视图方向的方法。然而,我似乎找不到一个不过时的明确答案。请问有人可以建议根据用户按下按钮时切换方向的最佳方法吗?

即我需要一些帮助来填补空白......

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山有枢 2024-12-28 01:02:39

苹果的指导方针不允许这样做。有一些技巧可以做到这一点,但使用它并不是一个好主意。

您的应用程序将在真实设备中运行,并且没有任何代码可以物理地转动手机。设备方向受到现实世界的约束,您不能强迫用户转动手机。

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.

朦胧时间 2024-12-28 01:02:39
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft

将方向更改为横向或纵向。

您可能还必须应用转换才能完成更改:

self.view.transform = CGAffineTransformRotate(self.view.transform, -(M_PI / 2.0));
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft

Change the orientation to Landscape or Portrait.

You might have to also apply a transformation to complete the change:

self.view.transform = CGAffineTransformRotate(self.view.transform, -(M_PI / 2.0));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文