限制在横幅视图中的视图突然跳跃而不是慢慢动画

时间:2015-09-20 19:48:35

标签: ios animation iad adbannerview

我正在尝试使用约束从底部到屏幕动画横幅视图。按钮附加到bannerview,它应始终与横幅保持相同的距离。这就是我得到的: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
        })
    }
}

1 个答案:

答案 0 :(得分:3)

而不是动画块中的self.view.layoutIfNeeded(),请致电banner.superview!.layoutIfNeeded()