2014-02-20 55 views
0

我需要你的幫助。 在我的應用程序中,我按下按鈕並開始動畫。在這個動畫之後,我想在不按任何其他按鈕的情況下自動更改視圖。 我該怎麼辦?如何在動畫後更改視圖?

這裏我的代碼,我認爲我是在正確的方式,但動畫無法啓動,只更改視圖和xcode不會給我一個錯誤消息。

- (IBAction)button { 

    [UIView animateWithDuration:2.5f animations:^{ 

     NSArray *playAnimation; 
     playAnimation= [[NSArray alloc] initWithObjects: 
         [UIImage imageNamed:@「image1.png"], 
         [UIImage imageNamed:@「image2.png"], 
         [UIImage imageNamed:@"image3.png"], 
         [UIImage imageNamed:@"image4.png"], 
         [UIImage imageNamed:@"image5.png"], 
         [UIImage imageNamed:@"image6.png"], 
         [UIImage imageNamed:@"image7.png"], 
         Nil]; 

    } 
     completion:^(BOOL finished) { 

    UIStoryboard *Scene1 = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
     UIViewController *Sc1 = [Scene1 instantiateViewControllerWithIdentifier:@"ViewController"]; 
     [self presentViewController:Sc1 animated:NO completion:nil]; 

    }]; 

} 

的幫助

+0

@rene我沒有錯誤消息,但動畫沒有啓動它只改變視圖 – user3242391

回答

0

大多數的動畫*方法非常感謝有需要完成塊兄弟表單。使用完成來做任何你想做的事情。

例如

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations; 

- 對 -

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 
0

取決於你如何開始動畫。請閱讀chaining UIView animations以獲得有關該主題的良好概述。

如果您使用的UIView動畫,設置動畫代表和animationDidStopSelector,如:

[UIView beginAnimations:@"Grow" context:self.btn]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationDuration:0.5f]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(doneAnimating:finished:context:)]; 
// Do stuff you want animated 
[UIView commitAnimations]; 

如果您使用CABasicAnimation,同樣的事情,只是不同的界面 - 設置委託和animationDidStop選擇如:

CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"]; 
anim.delegate = self; 
anim.animationDidStop = @selector(doneAnimating:finished:context:)]; 
anim.fromValue = [NSNumber numberWithDouble:0.01]; 
anim.toValue = [NSNumber numberWithDouble:1.0]; 
anim.duration = 0.5f; 
[layer addAnimation:anim forKey:@"grow"]; 

在這兩種情況下,當動畫結束-doneAnimating將調用:

-(void)doneAnimating:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    // Do whatever you want next 
} 
0

你可以做基本的UIView動畫。這些包括可以推送/呈現視圖的完成塊。

[UIView animateWithDuration:1.5f animations:^{ 
     // Perform animation here. 
     // ex. 
     [label setFrame:CGRectMake(0, 0, 320, 50)]; 
    } completion:^(BOOL finished) { 
     // Show new view. 
     [self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES]; 
    }]; 
+0

你好福雷斯,感謝你的幫助。這段代碼對我來說看起來非常有用,但是我嘗試了它,但它不起作用。我有一個框架動畫,我開始與IBAction – user3242391