设置UIView的框架不起作用

设置UIView的框架不起作用

本文介绍了设置UIView的框架不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 7中的frame-property有一个问题。
我想调整一些UIViews在 viewDidLoad - 我的 UIViewController ,但如果我这样做 int screenHeight = [[UIScreen mainScreen] bounds] .size.height;
[self.leftSideTableView setFrame:CGRectMake(0,0,320,screenHeight)];

高度设置为我想要的,直到方法结束,每一个其他方法,它是一直在之前!



它有什么问题,还是只是一个编译器或其他错误?

解决方案

必须将视图大小调整为 -viewDidLayoutSubviews:! p>

将视图框架更改放置到 -viewWillAppear: -viewDidLoad:将无法工作,因为视图尚未布局!


I have a problem with the frame-property in iOS 7.I wanna resize some UIViews in the viewDidLoad-method of my UIViewController, but if I do it like int screenHeight = [[UIScreen mainScreen] bounds].size.height;[self.leftSideTableView setFrame: CGRectMake(0, 0, 320, screenHeight)];the height is set as I want it till the end of the method, but in every other method it is as is has been before!

What's wrong with it or is it just a bug of the compiler or anything else?

解决方案

One has to put view resizing into -viewDidLayoutSubviews:! (documentation)

Placing view frame changes into -viewWillAppear: or -viewDidLoad: will not work, because the views are not laying out yet!

这篇关于设置UIView的框架不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 01:43