3 回答

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
你需要打電話 layoutIfNeeded
在動(dòng)畫(huà)塊中。實(shí)際上,Apple建議您在動(dòng)畫(huà)塊之前調(diào)用它一次,以確保所有掛起的布局操作都已完成。 您需要在 父視圖(如: self.view
),而不是附加約束的子視圖。這樣做將更新 全約束視圖,包括動(dòng)畫(huà)其他可能被限制為您更改了視圖A的約束的視圖(例如,視圖B附加到視圖A的底部,而您剛剛更改了視圖A的頂部偏移量,您希望視圖B與它一起動(dòng)畫(huà))
目標(biāo)-C
- (void)moveBannerOffScreen { [self.view layoutIfNeeded]; [UIView animateWithDuration:5 animations:^{ self._addBannerDistanceFromBottomConstraint.constant = -32; [self.view layoutIfNeeded]; // Called on parent view }]; bannerIsVisible = FALSE;}- (void)moveBannerOnScreen { [self.view layoutIfNeeded]; [UIView animateWithDuration:5 animations:^{ self._addBannerDistanceFromBottomConstraint.constant = 0; [self.view layoutIfNeeded]; // Called on parent view }]; bannerIsVisible = TRUE;}
SWIFT 3
UIView.animate(withDuration: 5) { self._addBannerDistanceFromBottomConstraint.constant = 0 self.view.layoutIfNeeded()}

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
文檔中的基本塊動(dòng)畫(huà)
[containerView layoutIfNeeded]; // Ensures that all pending layout operations have been completed[UIView animateWithDuration:1.0 animations:^{ // Make all constraint changes here [containerView layoutIfNeeded]; // Forces the layout of the subtree animation block and then captures all of the frame changes}];
updateConstraints
調(diào)用子視圖updateConstraint方法的動(dòng)畫(huà)塊
[self.view layoutIfNeeded];[self.subView setNeedsUpdateConstraints];[self.subView updateConstraintsIfNeeded]; [UIView animateWithDuration:1.0f delay:0.0f options:UIViewAnimationOptionLayoutSubviews animations:^{ [self.view layoutIfNeeded];} completion:nil];
- (void)updateConstraints{ // Update some constraints [super updateConstraints];}
UISwitch
UITextField
- 3 回答
- 0 關(guān)注
- 645 瀏覽
添加回答
舉報(bào)