此代码:
m_networkActivityView = [[[NSBundle mainBundle] loadNibNamed:@"NetworkActivityView" owner:self options:nil] objectAtIndex:0];
[self addSubview:m_networkActivityView];
m_networkActivityView.center = self.center;
m_networkActivityView.hidden = true;
让我知道这一点,因为它以桌子为中心,而不是屏幕,因此偏离中心:
这段代码
m_networkActivityView = [[[NSBundle mainBundle] loadNibNamed:@"NetworkActivityView" owner:self options:nil] objectAtIndex:0];
[self addSubview:m_networkActivityView];
m_networkActivityView.center = [self superview].center;
m_networkActivityView.hidden = true;
告诉我这个:
我真的不明白。
答案 0 :(得分:0)
我在评论中检查了superview
,并且它是null
,这就是它出现在角落里的原因。所以我这样做是为了解决它:
m_networkActivityView.center =
CGPointMake([UIScreen mainScreen].bounds.size.width / 2,
[UIScreen mainScreen].bounds.size.height / 2);