iPhone - 处理视图旋转
我正在创建一个尺寸为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将相关视图作为子视图添加到窗口中的主视图中,则会为您处理旋转和定位。
如果您确实需要将视图添加为关键窗口的子视图,我认为您需要调整视图的中心。
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.