UIView 子视图不改变方向
我有一个管理视图的视图控制器。
我将视图控制器子类添加为交换另一个视图的窗口的子视图。
我在 iPad 上运行横向模式。
该视图显然不知道它处于横向模式。它的框架很混乱。
我可以/应该做些什么来告诉它它是横向的,和/或方向已经改变。通常如何发生这种情况。为什么它没有发生?
我曾经将视图控制器放在 UITabBarController 中,并且在那里工作得很好。
I have a view controller which manages a view.
I'm adding the my view controller subclass as a subview of the window swapping out another view.
I'm running landscape mode on an iPad.
The view apparently doesn't know that its in landscape mode. Its frame is confused.
Is there something I can/should do to tell it that its in landscape, and/or that the orientation has changed. How does this normally happen. Why isn't it happening?
I used to have my view controller within a UITabBarController and it worked fine there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
覆盖:
Override:
您的 ViewController 没有收到旋转事件,因为您尚未呈现 viewController 但已在视图层次结构中添加了 viewController 的视图。
您的选项卡栏控制器以前负责将旋转事件转发到它管理的视图控制器,这就是它过去的工作方式。
但我建议将窗外的视图交换是一个坏主意。相反,您应该有一个主视图控制器,它接受旋转事件,然后根据当前方向交换此视图控制器中的视图。在进一步编码之前考虑重新设计。
Your ViewController is not getting rotation events because you have not presented the viewController but have added the viewController's view in the view hierarchy.
Your Tab bar controller previously used to take the responsibility to forward the rotation events to the view controller which it manages, that was how it used to work.
I would though suggest that swapping the view out of window is a bad idea. Instead you should have a main viewController which accepts the rotation events and then swap the view within this viewController based on the current orientation. Consider re-desiging before you code further.
我的问题是我的故事板覆盖了我现有的自定义编码应用程序委托。在我删除故事板文件和自定义生成的视图控制器代码后,它对我有用。
My problem was that my storyboard was overriding my existing custom coded app delegate. After I deleted the story board file, and custom generated view controller code, it worked for me.