先看这篇: http://jingyan.baidu.com/article/3c48dd349b0915e10be358a4.html?st=2&net_type=&bd_page_type=1&os=0&rst=&word=影视动画专业
转载; http://www.itstrike.cn/Question/a8cf36cd-9fd9-4c00-b2e4-a4da375961ce.html
我正在更新旧的应用程序与 AdBannerView 和没有广告时,它将关闭屏幕滑。有一则广告时张幻灯片在屏幕上。基本的东西。
旧样式,我在动画块中设置框架。我有新的风格, IBOutlet 的约束,确定的 Y 位置,在这种情况下它是从底部的超级景观,距离和修改该常数。
- (void)moveBannerOffScreen {
[UIView animateWithDuration:5
animations:^{
_addBannerDistanceFromBottomConstraint.constant = -32;
}];
bannerIsVisible = FALSE;
}
- (void)moveBannerOnScreen {
[UIView animateWithDuration:5
animations:^{
_addBannerDistanceFromBottomConstraint.constant = 0;
}];
bannerIsVisible = TRUE;
}
横幅移动,正是由于预期,但没有动画。
更新:我重新看了 WWDC12 视频"最佳做法,掌握自动布局",涵盖动画。它讨论了如何更新限制使用 CoreAnimation 。
enter image description here enter image description here
我试过用下面的代码,但得到完全相同的结果。
- (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;
}
注意到,我翻查过无数次和这正在执行的主线程上。
解决方法 1:
两个重要的注意事项:
您需要调用 layoutIfNeeded 动画块内。苹果公司其实建议你称之为一次之前要确保所有挂起的布局操作已完成的动画块
您需要调用它专门在父视图上 (例如 self.view ),不能在子视图具有附加到它的约束。这样做将更新所有约束视图,包括动画可能会认为,你改变了的约束约束其他视图 (如视图 B 附加到底部的视图 A 和您刚刚更改视图的顶部偏移量和你想要使用它进行动画处理的视图 B)
试试这个:
- (void)moveBannerOffScreen {
[self.view layoutIfNeeded]
[UIView animateWithDuration:5
animations:^{
_addBannerDistanceFromBottomConstraint.constant = -32;
[self.view layoutIfNeeded]; // Called on parent view
}];
bannerIsVisible = FALSE;
}
- (void)moveBannerOnScreen {
[UIView animateWithDuration:5
animations:^{
_addBannerDistanceFromBottomConstraint.constant = 0;
[self.view layoutIfNeeded]; // Called on parent view
}];
bannerIsVisible = TRUE;
}
评论框出错啦(1): 很抱歉,为了提升多说整体的服务质量,多说正在升级维护中,请耐心等待