如何让 UIView 自动调整大小规则在 viewDidLoad 上触发?
我在 Interface Builder 中使用支柱和弹簧创建了一个针对 iPad 的 UIView。一旦应用程序运行,当我更改设备方向时,自动调整大小就可以完美运行。但在启动时,UIView 具有横向尺寸(如我的 xib 中所示),无论设备启动的方向如何。如何让自动调整大小规则在 viewDidLoad 上触发,以便在用户启动视图时视图采用纵向形式应用程序与设备处于纵向方向?
谢谢!
I've created an iPad-targeted UIView in Interface Builder with struts and springs. Autoresizing works perfectly once the app is running, as I change the device orientation. But at startup, the UIView has its landscape sizing (as drawn in my xib) regardless of the orientation the device starts in. How do I get the autoresize rules to fire at viewDidLoad so that the view takes its portrait form if the user starts the app with the device in its portrait orientation?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setFrame 调用对我不起作用 - 因为简单地调用 mainViewController.view 会导致在处理 setFrame 之前触发 viewDidLoad 。
但是,在主视图控制器的 viewDidLoad 内部,您可以在进行其他计算之前调用它:
The setFrame call doesn't work from me - because simply calling mainViewController.view causes viewDidLoad to be triggered before the setFrame is processed.
However, inside the viewDidLoad for your main view controller, you can call this before you do other calculations:
这实际上非常简单。在您的 AppDelegate 中,只需向主视图控制器的视图发送一条消息来设置框架,如下所示:
This is actually really easy. In your AppDelegate, just send your main view controller's view a message to set the frame, like the following: