我旋转 UINavigationBar 的方式正确吗?
我有一个简单的 UIViewController,在 viewDidLoad 中我有:
_navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:_navigationBar];
_toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 416, 320, 44)];
[self.view addSubview:_toolbar];
在 didRotateFromInterfaceOrientation 中我放置:
_navigationBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44);
它可以工作,但我不太喜欢它的效果。有什么想法吗? 谢谢
I have a simple UIViewController where in the viewDidLoad I have:
_navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:_navigationBar];
_toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 416, 320, 44)];
[self.view addSubview:_toolbar];
In the didRotateFromInterfaceOrientation I put:
_navigationBar.frame = CGRectMake(0, 0, self.view.bounds.size.width, 44);
And it works but I don't like very much the effect which it did. Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在初始化每个视图时为每个视图设置适当的 autoresizingMask,而不是在视图旋转时手动更改其框架/边界/位置。
这样做,视图旋转将使其子视图自动调整大小(调整)。
例如:
或者您可以组合各种 UIViewAutoresizing 遮罩使用 |操作员。
当您在每个视图中调整弹簧时(在检查器窗口中),此属性与 IB 执行相同的操作
You supposed to set the appropriate autoresizingMask for each view when initializing it rather than changing its frame/bounds/position manually when the view rotates.
Doing so, the view rotation will make its subviews to be resized (adjusted) automatically.
for example:
or you can combine various UIViewAutoresizing masks using | operator.
This property does the same thing that IB when you adjust the springs in each view (In the inspector window)