2015-04-04 50 views
0

我有一个当前正在运行的动画。我跟着这个答案Xcode How to move an image up and down animation如何在特定时间段后触发我的动画?

我能够得到一个按钮触发的动画。我真正想要的是在特定的赛季结束后触发动画。当我继续在故事板中的特定视图时是否可以触发此动画?

动画是在我的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; 
} 

回答

2

实现一个 - (void)viewDidAppear;方法在你的UIViewController中并在那里调用你的动画函数。

当UIViewController视图被创建并且已经出现时,这个函数被调用。

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    NSLog(@"viewDidAppear"); 
    [masterViewController animate]; 
} 
相关问题