更改旋转时 UIScreen 的大小

发布于 2024-11-19 07:17:29 字数 660 浏览 6 评论 0原文

我正在制作一个 iPad 应用程序,它以纵向方向开始,但可以旋转到横向方向。在-(void) loadView中,我调用函数drawView。在drawView中,我有这行代码:

CGRect r = [[UIScreen mainScreen] bounds];

唯一的问题是,当我旋转到横向模式时,它不会自行更新,因此它仍然认为屏幕处于垂直方向,并且如果我想要文本视图扩展所有内容在整个屏幕上,它会在第 768 个像素处切断它,而不是第 1024 个像素。在 -(BOOL)shouldAutorotate... 我有 case UIInterfaceOrientationLandscapeRight: 和 case UIInterfaceOrientationLandscapeLeft:,并且我必须理想地放置 CGRect r = [[UIScreen mainScreen]bounds];在每种情况下,但我认为这不会起作用。有什么建议吗?感谢您的帮助!

编辑:我什至尝试过在其中调用函数

CGRect r = [[UIScreen mainScreen] bounds];

,但它仍然无法工作。我在它后面放置了一个 NSLog 并收到了响应,因此该应用程序肯定可以正常工作并且不会崩溃,但我仍然无法弄清楚这一点。有什么想法吗?感谢您的帮助!

I am making an iPad app that starts out in the portrait orientation but can rotate over to the landscape orientation. In -(void) loadView, I call the function drawView. In drawView, I have this line of code:

CGRect r = [[UIScreen mainScreen] bounds];

The only problem is that it doesn't update itself when I rotate to landscape mode, so it still thinks that the screen is in the vertical orientation and if I want a text view to extend all the across the entire screen, it cuts it off at the 768th pixel, instead of the 1024th pixel. In -(BOOL)shouldAutorotate... I have case UIInterfaceOrientationLandscapeRight: and case UIInterfaceOrientationLandscapeLeft:, and I would have to ideally place CGRect r = [[UIScreen mainScreen] bounds]; under each case, but I don't think that will work. Any suggestions? Thanks for your help!

Edit: I've even tried calling a function with

CGRect r = [[UIScreen mainScreen] bounds];

in it, but it still won't work. I place an NSLog after it and I received a response, so the app is definitely working properly and not crashing, but I am still unable to figure this out. Any ideas? Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

寂寞美少年 2024-11-26 07:17:29

我认为你的问题可以通过使用 UIViewautoresizingMask 来解决;

I think your problem could be solved by using the autoresizingMask of UIView;

不知所踪 2024-11-26 07:17:29

您的应用程序是否碰巧依赖 plist 进行配置?我见过一些应用程序,您可以在其中将方向键设置为 false 后获得横向图像。

Does your app happen to rely on plists for configuration? I've seen some apps where you can get landscape but only after you set an orientation key to false.

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