美文网首页
获取xib的autolayout后的frame

获取xib的autolayout后的frame

作者: 喵喵嘟噜啡 | 来源:发表于2018-12-11 14:59 被阅读12次

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

- (void)layoutSubviews
{
 [super layoutSubviews];
 [self setNeedsLayout];
 [self 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值就是正确的,故可以进行动画
}

相关文章

网友评论

      本文标题:获取xib的autolayout后的frame

      本文链接:https://www.haomeiwen.com/subject/qntehqtx.html