在init方法中获取UIView大小

在init方法中获取UIView大小,uiview,size,init,Uiview,Size,Init,在UIView的init方法中调用self.frame.size.height时,结果是0 UIView: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { NSLog(@"Content,init: %f",self.frame.size.height); ... UIView创建: m_content = [[Content alloc] i

在UIView的init方法中调用self.frame.size.height时,结果是0

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;

原因是帧(及其大小)是在init例程之后设置的

使用

而不是

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

其实一直都知道答案。我花了一些时间去弄清楚。我想我可以为那些因为写那篇文章而遇到问题的人节省一些时间。
m_content = [[Content alloc] init];
m_content.frame=self.frame;