2013-05-15 33 views
0

当我在我的UIView的init方法中调用self.frame.size.height时,结果为0。在初始化方法中获取UIView大小

的UIView:

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     NSLog(@"Content,init: %f",self.frame.size.height); 
... 

UIView的创建:

m_content = [[Content alloc] init]; 
m_content.frame=self.frame; 

回答

0

的原因是因为所述框架(和与它的大小)被设置初始化例程之后。

使用

m_content = [[Content alloc] initWithFrame:self.frame]; 

代替

m_content = [[Content alloc] init]; 
m_content.frame=self.frame; 
+0

其实知道答案一直。花费我一些时间来找出答案。我认为我通过发表这篇文章让人们省了些时间解决这个问题的人。 – asdf