iOS 中 NSNotificationCenter 的 if 语句

发布于 2024-12-12 08:33:49 字数 332 浏览 0 评论 0原文

我正在尝试在一个动画结束时开始另一个动画。

我正在检查这样的回调:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(animationDidStopNotification:) 
name:ImageAnimatorDidStopNotification 
object:animatorViewController];

如何制作一个 if 语句,让我在收到 ImageAnimatorDidStopNotification 时触发某些操作?

谢谢!

I'm trying start another animation when one ends.

I am checking for callbacks like this:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(animationDidStopNotification:) 
name:ImageAnimatorDidStopNotification 
object:animatorViewController];

How do I make an if statement that lets me do trigger something when ImageAnimatorDidStopNotification is received?

Thanks!

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

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

发布评论

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

评论(2

合约呢 2024-12-19 08:33:49

使用animationDidStop将动画链接在一起对于非常简单的场景非常有用。然而,对于任何更复杂的事情,它很快就会变得难以处理。

Apple 推荐的一种更好的方法是利用 CAMediaTiming 协议。

他们在 WWDC 2011 会议 421“核心动画要点”视频中给出了一个很好的例子。您会在上面的链接中找到它。您将需要一个开发者帐户才能访问它。

视频快进到 42:36,了解“通知和计时”提示。

Chaining animations together usinganimationDidStopis useful for very simple scenarios. However, for anything more complex, it quickly becomes unwieldy.

A much nicer approach as recommended by Apple, is to take advantage of theCAMediaTimingprotocol.

They give a great example in the WWDC 2011 videos in Session 421 "Core Animation Essentials". You'll find that in the link above. You will need a developer account to access that.

Fast forward in the video to 42:36 for the "Notifications and Timing" Tip.

绿光 2024-12-19 08:33:49

您没有发布足够的代码来了解您要做什么以及问题出在哪里。

如果您想使用 UIKit 链接两个(或更多)动画,请尝试使用 setAnimationDidStopSelector: 选择器。

- (void)startAnimating
{
    [UIView beginAnimations: @"AnimationOne" context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationOneDidStop:finished:context:)];
    /* animation one instructions */
    [UIView commitAnimations];
}

- (void)animationOneDidStop:(NSString*)animationID 
                   finished:(NSNumber*)finished 
                    context:(void*)context
{
    [UIView beginAnimations: @"AnimationTwo" context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationTwoDidStop:finished:context:)];
    /* animation two instructions */
    [UIView commitAnimations];
}

- (void)animationTwoDidStop:(NSString*)animationID 
                   finished:(NSNumber*)finished 
                    context:(void*)context
{
    [UIView beginAnimations:@"AnimationThree" context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    /* animation three instructions */
    [UIView commitAnimations];
}

You didn't post enough code to know what are you trying to do and where is the problem.

If you want to chain two (or more) animations with UIKit, try using setAnimationDidStopSelector: selector.

- (void)startAnimating
{
    [UIView beginAnimations: @"AnimationOne" context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationOneDidStop:finished:context:)];
    /* animation one instructions */
    [UIView commitAnimations];
}

- (void)animationOneDidStop:(NSString*)animationID 
                   finished:(NSNumber*)finished 
                    context:(void*)context
{
    [UIView beginAnimations: @"AnimationTwo" context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationTwoDidStop:finished:context:)];
    /* animation two instructions */
    [UIView commitAnimations];
}

- (void)animationTwoDidStop:(NSString*)animationID 
                   finished:(NSNumber*)finished 
                    context:(void*)context
{
    [UIView beginAnimations:@"AnimationThree" context:nil]; 
    [UIView setAnimationDuration:1.0]; 
    /* animation three instructions */
    [UIView commitAnimations];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文