對(duì)于視圖view來(lái)說(shuō),如果想獲取xib中自動(dòng)布局后的frame鞭执,需要在layoutSubviews方法中獲取自動(dòng)布局后的frame才是準(zhǔn)確的
- (void)layoutSubviews
{
[super layoutSubviews];
[self setNeedsLayout];
[self layoutIfNeeded];
//在這里獲取frame
}
對(duì)于viewController來(lái)說(shuō),如果想獲取xib中自動(dòng)布局后的frame滩愁,需要在-(void)viewDidLayoutSubviews方法中
- (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值就是正確的坊夫,故可以進(jìn)行動(dòng)畫
}