无法在 iPad 上正确旋转翻译后的 UIView
我有一个 UIViewController ,里面有两个 UIView,其布局(在 Interface Builder 中设置)是这样的(洋红色视图是 UIViewController 默认视图):
并且我将主视图添加到获得此效果的根视图(通过不显示将其 frame
放置在底部):
现在,当设备旋转时,我得到的是:
而我仍想隐藏较暗的视图。 这是我用来在它出现时隐藏它的代码(我在 viewDidLoad
方法中使用它):
- (void)hideAll:(float)time{
CGRect hiddenFrame = CGRectMake(0, 1024, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
}
它似乎可以工作,但是当我在旋转时调用它的变体时(在 willRotateToInterfaceOrientation:duration:
),什么也没有发生:
CGRect hiddenFrame = CGRectMake(0, 748, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
我错过了什么?我需要在 Interface Builder 中设置一些其他视图属性吗?
更新
在我看来,设备旋转后坐标系不会改变(即在纵向模式下设置在左上角的原点在顺时针旋转后将变为右上角)横向模式)
I have an UIViewController
that has two UIViews inside, whose layout (set in Interface Builder) is something like this (the magenta colored view is the UIViewController default view):
and I added the main view to a root view obtaining this effect (by not showing the darker view placing its frame
at the bottom):
Now when the device rotates, what I obtain is this:
whereas I'd like to still hide the darker view.
This is the code I use to hide it when it appears (I use it in the viewDidLoad
method):
- (void)hideAll:(float)time{
CGRect hiddenFrame = CGRectMake(0, 1024, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
}
and it appears to work, but when I call a variant of it when rotating (in willRotateToInterfaceOrientation:duration:
), nothing happens:
CGRect hiddenFrame = CGRectMake(0, 748, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
What am I missing? have I to set some other view property in Interface Builder?
UPDATE
It seems to me that the coordinate system does not change after the device has been rotated (ie the origin set in the upper-left corner in portrait mode will become the upper-right after a clockwise rotation in landscape mode)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 IB 中的支柱和弹簧。也许当您自动旋转时,将您固定在屏幕顶部的支柱会将您的框架移回顶部。
尝试将代码添加到 didRotateToInterfaceOrientation 方法中,以便它可以在旋转发生后运行。
Check your struts and springs in IB. It maybe that when you autorotate, the strut fixing you to the top of the screen moves your frame back to the top.
Try adding your code to the didRotateToInterfaceOrientation method so it can run after rotation has occurred.
为什么要更改框架来隐藏它,而不仅仅是
第二件事是您应该尝试设置“自动调整大小”面板来处理方向更改,而不是通过更改视图的框架。
希望我理解你的意思是正确的。
沙尼
Why to you change the frame to hide it, and not just
second thing is that you should try to set the "Autoresizing" panel to handle the orientation changes, and not by changing the frame of the view.
hope i understood you right.
shani
我遇到的问题可以通过两种方式面对(我希望这可以为将来的某人节省一些时间):
The problem I encountered can be faced in two ways (I hope this can save some time for someone in the future):