• 爱情文章
  • 亲情文章
  • 友情文章
  • 生活随笔
  • 校园文章
  • 经典文章
  • 人生哲理
  • 励志文章
  • 搞笑文章
  • 心情日记
  • 英语文章
  • 范文大全
  • 作文大全
  • 新闻阅读
  • 当前位置: 山茶花美文网 > 友情文章 > 正文

    iOS4下实现UIView动画结束后调用_动画轴的调用,可以通过

    时间:2020-05-29来源:山茶花美文网 本文已影响 山茶花美文网手机站

    在写代码时,发现原来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:)];

    [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];

    }

    }

    ];

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

    • 爱情文章
    • 亲情文章
    • 友情文章
    • 随笔
    • 哲理
    • 励志
    • 范文大全