第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何激活約束更改?

如何激活約束更改?

iOS
炎炎設(shè)計(jì) 2019-06-10 16:51:52
如何激活約束更改?我正在用AdBannerView當(dāng)沒(méi)有廣告的時(shí)候,它就會(huì)從屏幕上滑落。當(dāng)有一個(gè)廣告,它在屏幕上幻燈片?;镜臇|西。舊的風(fēng)格,我把框架設(shè)置在一個(gè)動(dòng)畫(huà)塊。新款式,我有一個(gè)IBOutlet對(duì)于確定Y位置的自動(dòng)布局約束,在這種情況下,它與SuperView底部的距離,并修改常量:- (void)moveBannerOffScreen {     [UIView animateWithDuration:5 animations:^{         _addBannerDistanceFromBottomConstraint.constant = -32;     }];     bannerIsVisible = FALSE;}- (void)moveBannerOnScreen {     [UIView animateWithDuration:5 animations:^{         _addBannerDistanceFromBottomConstraint.constant = 0;     }];     bannerIsVisible = TRUE;}橫幅的移動(dòng)和預(yù)期完全一樣,但是不動(dòng)畫(huà)。最新情況:我重新看了WWDC 12談?wù)莆掌?chē)布局的最佳實(shí)踐包括動(dòng)畫(huà)。討論如何使用共動(dòng)畫(huà): 我嘗試了以下代碼,但得到了完全相同的結(jié)果:- (void)moveBannerOffScreen {     _addBannerDistanceFromBottomConstraint.constant = -32;     [UIView animateWithDuration:2 animations:^{         [self.view setNeedsLayout];     }];     bannerIsVisible = FALSE;}- (void)moveBannerOnScreen {     _addBannerDistanceFromBottomConstraint.constant = 0;     [UIView animateWithDuration:2 animations:^{         [self.view setNeedsLayout];     }];     bannerIsVisible = TRUE;}另外,我檢查了很多次,這是在主線。
查看完整描述

3 回答

?
躍然一笑

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊

兩個(gè)重要的注意事項(xiàng):

  1. 你需要打電話layoutIfNeeded在動(dòng)畫(huà)塊中。實(shí)際上,Apple建議您在動(dòng)畫(huà)塊之前調(diào)用它一次,以確保所有掛起的布局操作都已完成。

  2. 您需要在父視圖(如:self.view),而不是附加約束的子視圖。這樣做將更新約束視圖,包括動(dòng)畫(huà)其他可能被限制為您更改了視圖A的約束的視圖(例如,視圖B附加到視圖A的底部,而您剛剛更改了視圖A的頂部偏移量,您希望視圖B與它一起動(dòng)畫(huà))

試試這個(gè):

目標(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()}


查看完整回答
反對(duì) 回復(fù) 2019-06-10
?
慕哥9229398

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊

我很感謝你給出的答案,但我認(rèn)為再深入一點(diǎn)會(huì)更好。

文檔中的基本塊動(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}];

但實(shí)際上,這是一個(gè)非常簡(jiǎn)單的場(chǎng)景。如果我想通過(guò)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];

updateConstraint方法在UIView子類(lèi)中被重寫(xiě),必須在方法的末尾調(diào)用Super。

- (void)updateConstraints{
    // Update some constraints

    [super updateConstraints];}

AutoLayout指南還有很多有待改進(jìn)的地方,但值得一讀。我自己把這個(gè)作為一個(gè)UISwitch用一對(duì)UITextFields有一個(gè)簡(jiǎn)單而微妙的折疊動(dòng)畫(huà)(0.2秒長(zhǎng))。如上文所述,在UIView子類(lèi)updateConstraint方法中處理子視圖的約束。


查看完整回答
反對(duì) 回復(fù) 2019-06-10
  • 3 回答
  • 0 關(guān)注
  • 645 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)