UIView大小/位置在iPad上无法像在iPhone上那样工作 [英] UIView size/position not working on iPad as on iPhone

查看:49
本文介绍了UIView大小/位置在iPad上无法像在iPhone上那样工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宽度为320px高度为40px的UIView,我想在其底部显示它,就像一个标签栏.

I have a UIView of size width=320px height=40px which I want to display at the bottom looking like a tab-bar.

我使用以下代码来完成此操作,并且在iPhone上可以正常工作.但是当我尝试使用iPad模拟器时,视图不会出现在屏幕上的任何地方.

I use the following code to accomplish this and it works fine on iPhone. But when I try the iPad simulator, the view does not appear anywhere on the screen.

buttonsView.frame=CGRectMake(
                                0,
                                self.view.frame.size.height - buttonsView.frame.size.height,
                                self.view.frame.size.width,
                                buttonsView.frame.size.height );

这会将视图扩展到屏幕的宽度,但保持其原始高度.

This stretches the view to the width of the screen but keeps it's original height.

我如何也可以直接在iPad上显示此节目?

How can I make this show right on my iPad also?

[UPDATE]

这发生在我的viewDidLoad中.

我现在有这个NSLog:

I have this NSLog now:

NSLog(@"buttonsView Width: \t%g\t%g\tHeight:\t%g\t%g",self.view.frame.size.width, buttonsView.frame.size.width, self.view.frame.size.height, buttonsView.frame.size.height);

带输出:
iPhone:

With output:
iPhone:

buttonsView宽度:320320高度:460 40

buttonsView Width: 320 320 Height: 460 40

iPad:

buttonsView宽度:768 768高度:1004 40

buttonsView Width: 768 768 Height: 1004 40

我还在页面顶部创建了另一个类似的视图,效果很好:

I also create another view like this for the top of the page which works fine:

dataView.frame=CGRectMake(
                             0,
                             0,
                             self.view.frame.size.width,
                             dataView.frame.size.height);

推荐答案

之所以发生这种情况,是因为为UIView设置了Auto Resizing.

This happened because the Auto Resizing was set for the UIView's.

要解决此问题,请设置Auto Resizing将其绑定到左上角.这样,每当您更改框架时,它都是相对于左上方像素的.

To fix, set the Auto Resizing to bind it to the top left corner. This way whenever you change the frame, it is relative to the top left pixel.

这篇关于UIView大小/位置在iPad上无法像在iPhone上那样工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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