UIView 子视图不改变方向

发布于 2024-09-18 20:11:38 字数 228 浏览 5 评论 0原文

我有一个管理视图的视图控制器。

我将视图控制器子类添加为交换另一个视图的窗口的子视图。

我在 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 技术交流群。

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

发布评论

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

评论(3

不顾 2024-09-25 20:11:38

覆盖:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}

Override:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}
dawn曙光 2024-09-25 20:11:38

您的 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.

没企图 2024-09-25 20:11:38

我的问题是我的故事板覆盖了我现有的自定义编码应用程序委托。在我删除故事板文件和自定义生成的视图控制器代码后,它对我有用。

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.

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