tha*_*har 10 iphone objective-c uiimageview ios
有没有一种方法可以检测动画何时完成?我想[nav setTitle:navItem]在动画结束时打电话.
下面是我的代码片段.希望问题很清楚,所以我可以得到一个解决方案,最好是一个例子.
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if(event.subtype == UIEventSubtypeMotionShake){
NSString *imageUrl = @"";
NSString *navItem = @"";
int randomNumber = arc4random() % 3;
switch (randomNumber) {
case 0:
imageUrl = @"pic1.png";
navItem = @"txt1";
break;
case 1:
imageUrl = @"pic2.png";
navItem = @"txt2";
break;
case 2:
imageUrl = @"pic3.png";
navItem = @"txt3";
break;
default:
break;
}
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"pic1.png"],
[UIImage imageNamed:@"pic3.png"],
[UIImage imageNamed:@"pic2.png"],
[UIImage imageNamed:@"pic1.png"],
[UIImage imageNamed:@"pic2.png"],
[UIImage imageNamed:@"pic3.png"],
[UIImage imageNamed:imageUrl],
nil];
UIImage *img = [UIImage imageNamed:imageUrl];
[imageview setImage:img];
[animation setAnimationRepeatCount:1];
animation.animationDuration = 1;
[animation startAnimating];
[nav setTitle:navItem];
}
}
Run Code Online (Sandbox Code Playgroud)
Mic*_*rry 10
您可以使用setAnimationDidStopSelector委托.
http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context {
/*Do stuff*/
}
Run Code Online (Sandbox Code Playgroud)
当 == NO 时动画结束[animation isAnimating]。
如果您想等到它完成但不阻止 UI:
while ([animation isAnimating]) {
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13592 次 |
| 最近记录: |