ios – UIView animateWithDuration和UIProgressView setProgress

ios – UIView animateWithDuration和UIProgressView setProgress,第1张

概述我想在10秒内将我的UIProgressView进度从0到1动画. 码: [UIView animateWithDuration:10.0 animations:^{ [_myProgressView setProgress:1 animated:YES];} completion:(BOOL finished)^{ if (finished) NSLog(@"animation 我想在10秒内将我的UIProgressVIEw进度从0到1动画.

码:

[UIVIEw animateWithDuration:10.0 animations:^{    [_myProgressVIEw setProgress:1 animated:YES];} completion:(BOol finished)^{    if (finished) NSLog(@"animation finished);}];

动画工作正常,除了完成和NSLog总是瞬间调用.

我试过animateWithDuration:withDelay:但延迟不被尊重并立即执行.

有人遇到同样的问题吗?

谢谢你的帮助

解决方法 这是一个老问题,但我仍然在这里发布解决方案.解决方案的确很简单.
所有你需要做的是:
[_myProgressVIEw setProgress:1];[UIVIEw animateWithDuration:10.0 animations:^{    [_myProgressVIEw layoutIfNeeded];} completion:^(BOol finished){    if (finished) NSLog(@"animation finished");}];

这是一个很好的解释,为什么事情正在为你工作不正确:
http://blog.spacemanlabs.com/2012/08/premature-completion-an-embarrassing-problem/

所以你不能使用setProgress:animated:方法为进度视图动画化,并获得完成块的所需行为.但是,只是在块内设置进度将不会动画化,因为进度不是一个动画的属性.

请参阅苹果文档,说明该属性必须具有动画性:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/clm/UIView/animateWithDuration:animations:

所以你只需更新动画块外的进度属性的值,然后在动画块内部进行视图的布局.

总结

以上是内存溢出为你收集整理的ios – UIView animateWithDuration和UIProgressView setProgress全部内容,希望文章能够帮你解决ios – UIView animateWithDuration和UIProgressView setProgress所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1095985.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存