ios4下实现uiview动画结束后调用
2014-11-14来源:

更改uiswitch上的text

为要更改text的uiswitch建立ib连接:例如myswitch,在代码中改变文字:

((uilabel *)[[[[[[self.myswitch subviews] lastobject] subviews] objectatindex:2] subviews] objectatindex:0]).text = @foo;

((uilabel *)[[[[[[self.myswitch subviews] lastobject] subviews] objectatindex:2] subviews] objectatindex:1]).text = @ba在写代码时,发现原来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];

}

}

];

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

更多信息请查看IT技术专栏

推荐信息
Baidu
map