我使用以下代码成功为启动画面创建了动画:
[super viewDidLoad];
AnimationimageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"splash1.png"],
[UIImage imageNamed:@"splash2.png"],
[UIImage imageNamed:@"splash3.png"],
[UIImage imageNamed:@"splash4.png"], nil];
[AnimationimageView setAnimationRepeatCount:1];
AnimationimageView.animationDuration=3;
[AnimationimageView startAnimating];
我将此代码与storyBoard连接。
我的问题是如何知道动画是否完成以传递到另一个视图。
答案 0 :(得分:2)
您可以像这样使用setAnimationDidStopSelector:
:
[UIView setAnimationDidStopSelector: @selector(animationDidStop: finished: context: )];
实现选择器:
- (void)animationDidStop: (NSString *)animationID finished:(NSNumber *)finished context: (void *)context
{
//your code here.
}
但是基于Apple Docs:
您可以根据需要指定动画委托 动画开始或停止时接收消息。打电话后 这个方法,你应该调用setAnimationWillStartSelector:和 setAnimationDidStopSelector:注册适当的方法 选择。默认情况下,动画委托设置为nil。
您主要使用此方法设置动画块的委托 使用begin / commit动画方法创建。调用此方法 从动画块外面什么都不做。
在iOS 4.0及更高版本中不鼓励使用此方法。如果你是 使用基于块的动画方法,您可以包含您的 委托的开始和结束代码直接在您的块内。
然而,Apple并未建议使用其他解决方案如果您不使用块;以及The Elements示例代码,is upgraded for iOS 6.0 SDK, and updated to adopt current best practices for Objective-C,Apple仍使用setAnimationDidStopSelector:
。
然而,对于这种沮丧here有一个很好的解释,这可能是因为Apple可能会更好地改进块动画,并可能在将来弃用setAnimationDidStopSelector
因此,如果您想使用块而不是当前方法,请执行以下操作:
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseIn
animations:^{
aView.alpha = 0.0;
}
completion:^(BOOL finished){
// Do your setAnimationDidStopSelector stuff here!
}];
答案 1 :(得分:2)
我将采用另一种方法并使用UIView现在支持的基于块的解决方案。特别是方法
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
可以通过修改代码来实现您想要的功能。请参阅此处的参考link to apple docs
答案 2 :(得分:0)
让我们试试这段代码
在viewDidLoad中调用此函数
[self performSelector:@selector(gotoNextView) withObject:nil afterDelay:3];
创建方法
-(void)gotoNextView
{
// move to next view code
}
答案 3 :(得分:-1)
尝试+(void)setAnimationDidStopSelector:(SEL)选择器