iOS学习笔记-如何获取xib的autolayout后的frame

来源:互联网 发布:小伙领证前悔婚 知乎 编辑:程序博客网 时间:2024/05/22 16:38

对于视图view来说,如果想获取xib中自动布局后的frame,需要在layoutSubviews方法中获取自动布局后的frame才是准确的

- (void)layoutSubviews{ [super layoutSubviews]; [self.contentView setNeedsLayout]; [self.contentView layoutIfNeeded]; //在这里获取frame}

对于viewController来说,如果想获取xib中自动布局后的frame,需要在-(void)viewDidLayoutSubviews,-(void)viewWillLayoutSubviews方法中

- (void)viewDidLayoutSubviews{    [super viewDidLayoutSubviews];    self.moveItem.frame = CGRectMake(0, 0, self.scanView.frame.size.width, 10); //建立视图需要在viewdidload等方法中,在这里指定frame    [UIView animateKeyframesWithDuration:2 delay:0 options:UIViewKeyframeAnimationOptionRepeat animations:^{        self.moveItem.frame = CGRectMake(0, self.scanView.frame.size.height - 10, self.scanView.frame.size.width, 10);;    } completion:nil];//这里的frame值就是正确的,故可以进行动画}
0 0
原创粉丝点击