UITabBar 更改旋转时的所有视图
我有一个具有多个视图的选项卡栏控制器。每个视图都有一个工具栏。我添加了代码以将背景图像应用到工具栏。
我还在 viewdidLoad 中添加了代码,在设备旋转时在每个视图上触发,以便我可以为横向模式应用不同的背景图像:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
如果我运行应用程序并旋转,第一个视图可以工作,但随后转到其他选项卡会导致didRotate 方法不会触发,因为设备已经旋转。
如何让设备旋转时所有视图都更新?
I have a tab bar controller with multiple views. Each of the views has a toolbar. I added code to apply a background image to the toolbar.
I also added code, in viewdidLoad, on each view to fire when the device is rotated so I can apply a different background image for landscape mode:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
If I run the app and rotate, the first view works, but then going to other tabs causes the didRotate method to not fire, since the device has already rotated.
How can I make all the views update when the device rotates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该做的是检查
viewWillAppear:
上的interfaceOrientation
并根据需要重新布局 UI。What you should do is to check the
interfaceOrientation
onviewWillAppear:
and re-layout the UI if needed.您不一定需要通知。您可以使用两种方法来完成此操作
,
例如,要使 tabBar 在横向模式下隐藏但不在纵向模式下隐藏,请使用以下命令:
You do not necessarily need notifications. You can accomplish this using the two methods
and
For example, to make the tabBar hide in landscape mode but not in portrait, use this: