受制于横幅视图的视图会突然跳转而不是缓慢地动画化

views constrained to banner view jump suddenly instead of slowly animating

我正在尝试使用约束为从底部到屏幕的横幅视图设置动画。该按钮附加到横幅视图,它应始终与横幅保持相同的距离。这就是我得到的:https://vid.me/F008 如您所见,按钮突然跳动,但我希望它使用 UIView.animateWithDuration 方法缓慢移动。这是我的代码

@IBOutlet weak var bannerToBottomGuideConstraint: NSLayoutConstraint!
@IBOutlet weak var buttonToBannerConstraint: NSLayoutConstraint!


@IBOutlet weak var bannerView: ADBannerView!


override func viewDidLoad() {
    super.viewDidLoad()

    self.canDisplayBannerAds = true
    bannerToBottomGuideConstraint.constant -= CGRectGetHeight(bannerView.bounds)
    bannerView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0)
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    let time = 0.6

    if banner.bannerLoaded == false{
        self.view.layoutIfNeeded()
        bannerToBottomGuideConstraint.constant += CGRectGetHeight(bannerView.bounds)
        UIView.animateWithDuration(time, animations: {
            self.view.layoutIfNeeded()
            }, completion: {_ in
        })
    }
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {

    if bannerView.bannerLoaded{
        bannerToBottomGuideConstraint.constant -= CGRectGetHeight(bannerView.bounds)
        UIView.animateWithDuration(0, animations: {
            self.view.layoutIfNeeded()
            }, completion: {_ in
        })
    }
}

而不是在动画块中调用 self.view.layoutIfNeeded(),调用 banner.superview!.layoutIfNeeded()