【问题标题】:After Completion of Animation want to call some methods动画完成后想调用一些方法
【发布时间】:2012-01-05 10:45:34
【问题描述】:

在我的 iPhone 应用程序中

我正在制作某些动画。 喜欢

[UIView beginAnimations:@"stalk" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.frame=originalSelf;
    [UIView commitAnimations];

这个动画完成后我想调用一些方法...

我知道一些关于块动画或

DidStopAnimation 通知

我该怎么做.... 谢谢..

【问题讨论】:

    标签: iphone objective-c xcode cocoa-touch animation


    【解决方案1】:

    在 iOS 4 及更高版本上,建议为此使用块:

    [UIView animateWithDuration:1 
                         animations:^{
                             self.frame=originalSelf;} 
                         completion:^(BOOL finished){
    
                            //My method call;
                         }
         ];
    

    【讨论】:

      【解决方案2】:

      尝试使用

      [UIView beginAnimations:@"stalk" context:nil];
      [UIView setAnimationDuration:1];
      [UIView setAnimationBeginsFromCurrentState:YES];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDidStopSelector:@selector(afterAnimationStops)]
      self.frame=originalSelf;
      [UIView commitAnimations];
      

      然后你就可以实现方法了

      -(void)afterAnimationStops{
      
      }
      

      【讨论】:

        【解决方案3】:

        使用这个:

        animateWithDuration:animations:completion:
        

        这里有更多信息:http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

        这是一个例子:

        [UIView animateWithDuration:1.0 animations:^{self.frame=originalSelf;} completion:^(BOOL finished){/*have your completion code here*/}];
        

        【讨论】:

          猜你喜欢
          • 2014-11-16
          • 1970-01-01
          • 1970-01-01
          • 2012-03-06
          • 1970-01-01
          • 1970-01-01
          • 2019-09-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多