iPhone 5 上的 UIView 高度不正确 [英] UIView height is not right on iPhone 5

查看:28
本文介绍了iPhone 5 上的 UIView 高度不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIPickerView 一遍又一遍地迁移我的应用程序.在 viewDidLoad 方法中,我创建了选择器并将它的 y 原点设置为 self.view.frame.size.height 以便它不在屏幕上.然后我只是在需要时将其向上移动.

I am migrating my apps over and on one I use a UIPickerView. In the viewDidLoad method I create the picker and set it's y origin to be self.view.frame.size.height so that it is off screen. Then I just move it up when needed.

在 iPhone 5 上 self.view.frame.size.height 仍然返回 480 但 UIView 正确填充屏幕.

On the iPhone 5 self.view.frame.size.height is still returning 480 yet the UIView fills the screen correctly.

我什至尝试使用 CGRectGetHeight(self.view.bounds) 认为它可能返回不同的东西......没有骰子.关于为什么会发生这种情况的任何想法.

I've even tried using CGRectGetHeight(self.view.bounds) thinking that it may return something different...no dice. Any ideas as to why this maybe occurring.

推荐答案

那是因为您在视图笔尖中选择的大小将一直使用到 viewWillAppear: (BOOL) 动画 方法.然后它将采用正确的尺寸.

That is because the size you selected in the view's nib will be used until viewWillAppear: (BOOL) animated method. Then it will take the correct size.

但是您可以使用以下代码来获得正确的大小,因为 viewDidLoad 被调用:

However you can use the following code to have the correct size since viewDidLoad is called:

CGSize viewSize = [[UIScreen mainScreen] bounds].size;
viewSize = CGSizeMake(viewSize.width, viewSize.height - STATUS_BAR_HEIGHT);

STATUS_BAR_HEIGHT 是 20,但这取决于您的应用.您可能需要也可能不需要添加该行.

STATUS_BAR_HEIGHT is 20 but it depends on your app. You may or may not need to add that line.

编辑

使用 mainScreen 边界的问题是框架不会随着方向改变而改变.这就是它的设计方式.您可以通过以下方式解决:

The problem with using mainScreen bounds is that the frame doesn't change on orientation change. That is the way it is designed. You can work it out with the following:

    CGSize viewSize = [[UIScreen mainScreen] bounds].size;

    if(UIInterfaceOrientationIsLandscape(CURRENT_ORIENTATION)){
        viewSize = CGSizeMake(viewSize.height, viewSize.width - STATUS_BAR_HEIGHT);

    } else {
        viewSize = CGSizeMake(viewSize.width, viewSize.height - STATUS_BAR_HEIGHT);
    }

CURRENT_ORIENTATION[[UIApplication sharedApplication] statusBarOrientation];

这篇关于iPhone 5 上的 UIView 高度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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