强制 autoresizingMask 应用于 UIView

发布于 2024-09-16 04:05:15 字数 172 浏览 6 评论 0原文

我有一个通知视图,在启动后将其添加到应用程序的窗口中,因此它悬停在所有其他视图之上。

当用户旋转设备时,视图不会像 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 技术交流群。

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

发布评论

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

评论(3

虚拟世界 2024-09-23 04:05:15

我发现添加到应用程序窗口的视图甚至不会旋转,更不用说调整大小了。

这是针对 Orientation in a UIView displayed to a UIWindow 的询问和回答:将通知视图添加到窗口的第一个子视图。

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) 
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];

而且,它还解决了您的问题,您的通知视图现在应该根据其掩码调整大小。

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.

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) 
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];

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.

守护在此方 2024-09-23 04:05:15

您是否

view.autoresizesSubviews = YES;

在适当的超级视图中设置了:?

Did you set:

view.autoresizesSubviews = YES;

in the appropriate superview?

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