我有一个正在运行的动画。我按照这个答案Xcode How to move an image up and down animation
我能够通过按钮触发动画。我真正想要的是在特定的segue之后触发动画。当我转到故事板中的特定视图时,是否可以触发此动画?
动画位于我的ViewController
实现中的方法中。
-(void)animatePicker
{
NSLog(@"Animate");
CGPoint startPoint = (CGPoint){100.f, 100.f};
CGPoint middlePoint = (CGPoint){400.f, 400.f};
CGPoint endPoint = (CGPoint){600.f, 100.f};
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, startPoint.x, startPoint.y);
CGPathAddLineToPoint(thePath, NULL, middlePoint.x, middlePoint.y);
CGPathAddLineToPoint(thePath, NULL, endPoint.x, endPoint.y);
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration = 3.f;
animation.path = thePath;
[pickerCircle.layer addAnimation:animation forKey:@"position"];
pickerCircle.layer.position = endPoint;
}
答案 0 :(得分:2)
实现 - (void)viewDidAppear;你的UIViewController中的方法,并在那里调用你的动画功能。
当创建UIViewController视图并且也出现时,将调用此函数。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"viewDidAppear");
[masterViewController animate];
}