首页 > 网站 > 建站经验 > 正文

iOS4,下实现UIView动画结束后调用

2019-11-02 14:41:15
字体:
来源:转载
供稿:网友

   在写代码时,发现原来3.1.3下经常用的uiview动画结束后调用事件的方法居然不起作用了,摸索了一下,发现ios4下对uivew的animation处理已经有新的方式了,和大家分享一下:

  代码功能:在myview向下移出屏幕的动画结束后,触发事件再将myview移除掉。

  ios4以前的用法:

  [UIView beginAnimations:@"View Remove" context:nil];

  UIView setAnimationDelegate:self];

  [UIView setAnimationDidStopSelector:@selector(animationFinish:animationID:finished:context:)];

  

童话村电影网[www.aikan.tv/special/tonghuacundianying/]
[UIView setAnimationDuration:0.3f];

  [UIView setAnimationCurve:UIViewAnimationCurveLinear];

  myView.center = CGPointMake(myView.center.x, myView.center.y+480.0);

  UIView commitAnimations];

  - (void)animationFinish:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

  if (animationID == @"View Remove") {

  [myView removeFromSuperview];

  }

  }

  Xcode的document已经明确说了setAnimationDidStopSelector :”Use of this method is discouraged in iPhone OS 4.0 and later. You should use the block-based animation methods instead.“,看来这种方法是行不通了,反正在我的模拟器上是不行了,以下是ios4中的实现方法:

  [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveLinear

  animations:^{

  settingView.center = CGPointMake(myView.center.x, myView.center.y+480.0);

  }

  completion:^(BOOL finished){

  if (finished){

  [myView removeFromSuperview];

  }

  }

  ];

  看起来更加简洁方便了,但逻辑似乎没有原来好理解了。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表