IOS:关于动画的问题

发布于 2024-11-28 18:04:41 字数 301 浏览 0 评论 0原文

我有这个代码: successview 是我的视图,它以 alpha 0.00 开始,但是当它使用自动反转完成动画时,successview 变为 alpha 1.00...为什么?

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationRepeatAutoreverses:YES];
[successView setAlpha:1.00];
[UIView commitAnimations];

I have this code:
successview is my view and it start with alpha 0.00 but when it finish the animation with autoreverse, successview become with alpha 1.00...why?

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationRepeatAutoreverses:YES];
[successView setAlpha:1.00];
[UIView commitAnimations];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏末 2024-12-05 18:04:41

一种方法是制作两种不同的动画:一种动画的 alpha 值逐渐变为 1.0,另一种动画从 1.0 回到 0。

使用 的 animateWithDuration:animations:completion: 方法UIView 来完成这个任务。您可以在完成块中执行相反的操作。

类似的内容:

[UIView animateWithDuration:0.2
     animations:^{view.alpha = 1.0;}
     completion:^(BOOL finished){ 

        [UIView animateWithDuration:0.2
                         animations:^{view.alpha = 0;}];

     }];

请参阅 UIView 文档以获取有关

One approach is to do two different animations: One that progresses towards an alpha value of 1.0 and then another that goes from 1.0 back to 0.

Use the animateWithDuration:animations:completion: method of the UIView to accomplish this. You can do the reverse in the completion block.

Something along the lines of:

[UIView animateWithDuration:0.2
     animations:^{view.alpha = 1.0;}
     completion:^(BOOL finished){ 

        [UIView animateWithDuration:0.2
                         animations:^{view.alpha = 0;}];

     }];

See UIView documentation for more details on animations.

快乐很简单 2024-12-05 18:04:41

它在文档中:

如果将自动反转与重复计数(可使用 setAnimationRepeatCount: 方法设置)结合起来,则可以创建在新旧值之间来回移动指定次数的动画。但是,请记住,重复计数表示完整循环的数量。如果您指定一个整数(例如 2.0),动画将在旧值处结束,然后视图立即更新自身以显示新值,这可能会令人不舒服。如果您希望动画在新值(而不是旧值)处结束,请将重复计数值添加 0.5。这为动画添加了额外的半个周期。

更新:读取了错误的代码,但如果您的目标是 iOS 4.0 及更高版本,文档建议您使用 animateWithDuration:delay:options:animations:completion:

It's in the docs:

If you combine autoreversing with a repeat count (settable using the setAnimationRepeatCount: method), you can create animations that shift back and forth between the old and new values a specified number of times. However, remember that the repeat count indicates the number of complete cycles. If you specify a whole number such as 2.0, the animation ends on the old value, which is followed by the view immediately updating itself to show the new value, which might be jarring. If you want the animation to end on the new value (instead of the old value), add 0.5 to the repeat count value. This adds an extra half cycle to the animation.

Update: read wrong your code, but docs suggest that you use animateWithDuration:delay:options:animations:completion: instead if you are targeting iOS 4.0 and later.

愚人国度 2024-12-05 18:04:41

如果有人感兴趣,这里是 Swift 代码:

UIView.animate(withDuration: 0.2, animations: {
     view.alpha = 1
}) { (finished) in
      UIView.animate(withDuration: 0.2, animations: {
          view.alpha = 0
      }) 
}

If someone is interested, here's Swift code:

UIView.animate(withDuration: 0.2, animations: {
     view.alpha = 1
}) { (finished) in
      UIView.animate(withDuration: 0.2, animations: {
          view.alpha = 0
      }) 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文