iPhone - 处理视图旋转

发布于 2024-09-25 01:24:33 字数 543 浏览 0 评论 0原文

我正在创建一个尺寸为 320 像素宽度和 120 像素高度的小型 UIView。 我使用以下代码将视图添加到最顶部的窗口。

baseview.frame = CGRectMake(0,20,320,120);
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
[window addSubview:baseView];    
[window bringSubviewToFront:baseView];

上面的代码显示了状态栏下方的视图,它符合预期。 当应用程序的方向为纵向时,此功能工作正常。但是当应用程序的方向是倒置纵向时,我要添加一行代码来旋转视图,那就是

[baseView setTransform:CGAffineTransformMakeRotation(-M_PI/2)];

但是现在,我看到的是应用程序底部的视图(而不是看到状态栏下方的顶部) )并且基本视图旋转并正确显示,除了底部的位置。我应该如何处理这种情况以在状态栏下显示视图。

I'm creating a small UIView of size 320 pixels width and 120 pixels height.
I'm using following code to add the view to top most window.

baseview.frame = CGRectMake(0,20,320,120);
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
[window addSubview:baseView];    
[window bringSubviewToFront:baseView];

The above code is showing a view below the status bar and it is as expected.
This is working fine when the app's orientation is portrait. But when the app's orientation is inverted portrait, i'm adding one more line of code to rotate the view and that is

[baseView setTransform:CGAffineTransformMakeRotation(-M_PI/2)];

But now, I'm seeing the view at the bottom of the application (instead of seeing at the top below status bar) and the baseview is rotate and appearing properly except the position at the bottom. How should I handled this situation to show the view under the status bar.

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

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

发布评论

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

评论(1

吐个泡泡 2024-10-02 01:24:33

如果您将相关视图作为子视图添加到窗口中的主视图中,则会为您处理旋转和定位。

如果您确实需要将视图添加为关键窗口的子视图,我认为您需要调整视图的中心。

If you add the view in question as a subview to the main view in the window, the rotation and positioning would be taken care of for you.

If you do need to add the view as a subview of the key window, I think you need to tweak the center of the view.

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