网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 iOS4下实现UIView动画结束后调用
范文
    在写代码时,发现原来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];
    }
    }
    ];
    看起来更加简洁方便了,但逻辑似乎没有原来好理解了。
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/22 4:36:01