I'm updating an old app with an AdBannerView
and when there is no ad, it slides off screen. 我正在使用AdBannerView
更新一箇舊應用,當沒有廣告時,它會滑出屏幕。 When there is an ad it slides on screen. 出現廣告時,它會在屏幕上滑動。 Basic stuff. 基本的東西。 app
Old style, I set the frame in an animation block. 舊樣式,我將幀設置在動畫塊中。 New style, I have a IBOutlet
to the auto-layout constraint which determines the Y position, in this case it's distance from the bottom of the superview, and modify the constant: 新樣式,我對自動佈局約束有一個IBOutlet
,它肯定Y位置,在這種狀況下,它是距父視圖底部的距離,並修改常量: ide
- (void)moveBannerOffScreen { [UIView animateWithDuration:5 animations:^{ _addBannerDistanceFromBottomConstraint.constant = -32; }]; bannerIsVisible = FALSE; } - (void)moveBannerOnScreen { [UIView animateWithDuration:5 animations:^{ _addBannerDistanceFromBottomConstraint.constant = 0; }]; bannerIsVisible = TRUE; }
And the banner moves, exactly as expected, but no animation. 橫幅徹底按預期移動,但沒有動畫。 佈局
UPDATE: I re-watched WWDC 12 talk Best Practices for Mastering Auto Layout which covers animation. 更新:我從新觀看了WWDC 12的「精通自動佈局的最佳實踐」,其中涵蓋了動畫。 It discusses how to update constraints using CoreAnimation : 它討論瞭如何使用CoreAnimation更新約束: 動畫
I've tried with the following code, but get the exact same results: 我嘗試使用如下代碼,但獲得的結果徹底相同: this
- (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; }
On a side note, I have checked numerous times and this is being executed on the main thread. 附帶一提,我已經檢查了不少次,而且這是在主線程上執行的。 spa