强制 autoresizingMask 应用于 UIView
我有一个通知视图,在启动后将其添加到应用程序的窗口中,因此它悬停在所有其他视图之上。
当用户旋转设备时,视图不会像 UIViewController 所拥有的那样自动调整大小。
有没有办法手动请求应用视图的 autoresizingMask ?或者,如何在设备旋转时调整没有视图控制器的视图的大小?
I have a notification view which I'm adding to the application's window after launch, so it hovers above all other views.
When the user rotates the device, the view does not autoresize like those owned by a UIViewController
.
Is there a way to manually ask for the view's autoresizingMask
to be applied? Or, alternatively, how can I have a view with no view controller be resized on device rotation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现添加到应用程序窗口的视图甚至不会旋转,更不用说调整大小了。
这是针对 Orientation in a UIView displayed to a UIWindow 的询问和回答:将通知视图添加到窗口的第一个子视图。
而且,它还解决了您的问题,您的通知视图现在应该根据其掩码调整大小。
I found that views added to the application window don't even rotate, let alone resize.
This was asked and answered for Orientation in a UIView added to a UIWindow: add the notification view to the first subview of the window.
And, it also solves your problem, your notification view should now be resized in accordance with its masks.
autoResizingMask 本身与旋转没有任何关系。它只是定义当其父视图调整大小时应如何调整视图的大小。
如果您添加一个顶级视图控制器,其视图与窗口大小相同并且包含所有其他视图,它应该可以工作。那么您的通知视图将是顶级视图的子视图(连接到视图控制器),并且应该自动旋转。
autoResizingMask doesn't have anything to do with rotation per se. It just defines how the view should be sized when its superview is resized.
It should work if you add a top-level view controller, with a view the same size as the window and which contains all other views. Then your notification view will be a subview of the toplevel view (connected to a view controller), and should autorotate.
您是否
在适当的超级视图中设置了:?
Did you set:
in the appropriate superview?