在 UINavigationController 上横向加载 UIDatePicker [英] Loading a UIDatePicker in Landscape on a UINavigationController

查看:26
本文介绍了在 UINavigationController 上横向加载 UIDatePicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个支持自动旋转的自定义 UINavigationController.我在我的一个视图上也有一个 UIDatePicker,我把它扔到导航控制器的堆栈上.如果我以纵向方式启动日期选择器视图然后旋转它,则自动旋转工作.如果我尝试以横向方式加载日期选择器视图,则视图会一团糟.如果它不支持旋转并且框架只有大约一半的选择器可见且偏离中心,则看起来会如此.

I have a custom UINavigationController that supports auto-rotate. I also have a UIDatePicker on one of my views that I throw onto the stack of the Navigation controller. The auto-rotate works if I start the date picker view in portrait and then rotate it. If I try load the date picker view in landscape to begin with, the view is all messed up. It looks like it would if it didn't support rotation and the frame only has about half of the picker visible and off center.

我尝试制作我自己的支持自动旋转的日期选择器,以防出现问题,我尝试创建两个不同的视图并将它们交换出来,并且我尝试更改 ViewWillAppear 上的视图框架大小方法.到目前为止,他们似乎都没有为我工作.

I've tried making my own date picker that supports auto-rotate in case that was the problem, I've tried creating two different views and swapping them out, and I've tried changing the view frame size on the ViewWillAppear method. None of them seem to be working for me as of yet.

有人对如何让日期选择器在导航控制器上正确显示在横向上有任何建议吗?我可能忽略了一些简单的问题,答案就在我面前,但我没有找到.

Anyone have any suggestions on how to get the date picker to show up in landscape correctly on a navigation controller? I probably am overlooking something simple and the answer is right in front of me, but I'm not finding it.

推荐答案

我遇到了同样的问题.当您在横向加载视图时,UIPicker 无法正确呈现.我花了几个小时试图找到解决方法,直到我从 此页面来自 Llamagraphics 中找到了解决方法.您在具有选择器的视图控制器的 viewDidLoad 中添加此代码:

I ran into the same problem. When you load a view while already in Landscape orientation the UIPicker is not rendered correctly. I spent several hours trying to find a workaround until I found a fix from this page from Llamagraphics. You add this code in viewDidLoad of the view controller that has the picker:

for (UIView* subview in myPicker.subviews) {
    subview.frame = myPicker.bounds;
}

访问网页了解更多详情.谢谢斯图尔特!

Visit the webpage for more details. Thank you Stuart!

这篇关于在 UINavigationController 上横向加载 UIDatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆