访问方法后的UIImageView动画完成
问题描述:
我已经装入,我通过一个周期动画一个UIImageView图像阵列。图像已经显示之后,我想一个 @选择
,以便关闭当前视图控制器调用。这些图像动画罚款与此code:
I have an array of images loaded into a UIImageView that I am animating through one cycle. After the images have been displayed, I would like a @selector
to be called in order to dismiss the current view controller. The images are animated fine with this code:
NSArray * imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"HowTo1.png"],
[UIImage imageNamed:@"HowTo2.png"],
nil];
UIImageView * instructions = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
instructions.animationImages = imageArray;
[imageArray release];
instructions.animationDuration = 16.0;
instructions.animationRepeatCount = 1;
instructions.contentMode = UIViewContentModeBottomLeft;
[instructions startAnimating];
[self.view addSubview:instructions];
[instructions release];
16秒之后,我想叫的方法。我看着的UIView
类方法 setAnimationDidStopSelector:
,但我不能让它与我当前的动画实施工作。有什么建议?
After the 16 seconds, I would like a method to be called. I looked into the UIView
class method setAnimationDidStopSelector:
but I cannot get it to work with my current animation implementation. Any suggestions?
感谢。
答
使用 performSelector:withObject:afterDelay:
:
[self performSelector:@selector(animationDidFinish:) withObject:nil
afterDelay:instructions.animationDuration];
或使用 dispatch_after
:
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, instructions.animationDuration * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self animationDidFinish];
});