2013-10-30 152 views
0

我有按鈕page 1當我點擊按鈕我正在執行一些動畫和導航到新頁面說Page 2UIButton點擊崩潰的應用程序

page 2有取消按鈕,當我點擊,我想回到我的先行頁面,即Page 1,但點擊取消按鈕我的應用程序崩潰。

這裏是Page 1:名稱頁CRViewController的是對Page 2:頁RegistraionViewController的名稱

- (IBAction)ClickMe:(id)sender { 
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init]; 

    CATransition *transitionAnimation = [CATransition animation]; 
    [transitionAnimation setDuration:1]; 
    [transitionAnimation setType:@"push"]; 
    [transitionAnimation setSubtype:kCATransitionFromBottom]; 
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; 

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom]; 
    [self.view addSubview:secondController.view]; 
} 

代碼我的示例代碼(在其崩潰的點擊。)

- (IBAction)Click:(id)sender { 
    CRViewController *secondController = [[CRViewController alloc] init]; 

    CATransition *transitionAnimation = [CATransition animation]; 
    [transitionAnimation setDuration:1]; 
    [transitionAnimation setType:@"push"]; 
    [transitionAnimation setSubtype:kCATransitionFromTop]; 
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; 

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom]; 
    [self.view addSubview:secondController.view]; 
} 
+0

當應用程序崩潰時,是否有任何錯誤信息? – dandan78

+0

@Krunal:顯示如何創建取消按鈕。 – TamilKing

+0

不,它只在我的日誌中顯示'lldb' – Krunal

回答

1

試試這個:

- (IBAction)ClickMe:(id)sender { 
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init]; 
    [self.navigationController pushViewController:secondController animated:YES]; 
} 


- (IBAction) Click:(id)sender {  
    [self.navigationController popViewControllerAnimated:YES];  
} 

編輯:
對不起。如果你想定製一些的UIViewController過場動畫,見下圖:
UIViewController transition - objective-c
http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
或者你可以試試這個:

- (IBAction)ClickMe:(id)sender { 
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init]; 

    CATransition *transitionAnimation = [CATransition animation]; 
    [transitionAnimation setDuration:1]; 
    [transitionAnimation setType:@"push"]; 
    [transitionAnimation setSubtype:kCATransitionFromBottom]; 
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; 

    [self.navigationController.view.layer addAnimation:transitionAnimation forKey:nil]; 
    [self.navigationController pushViewController:secondController animated:NO]; 
} 

- (IBAction)Click:(id)sender { 
    CRViewController *secondController = [[CRViewController alloc] init]; 

    CATransition *transitionAnimation = [CATransition animation]; 
    [transitionAnimation setDuration:1]; 
    [transitionAnimation setType:@"push"]; 
    [transitionAnimation setSubtype:kCATransitionFromTop]; 
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; 

    [self.navigationController.view.layer addAnimation:transitionAnimation forKey:nil]; 
    [self.navigationController popToViewController:secondController animated:NO]; 
} 
+0

我想要一些動畫。不推和流 – Krunal

+0

我試過這段代碼,它工作。你應該確保你的控制器層次結構中有navigationController。 – Vincent

+0

動畫來了,但動畫後它加載相同的文件 – Krunal

0

你的問題是在撒謊的地方,因爲子視圖。我試過你的代碼。

我在我的項目中用下面的代碼做了一些動畫,希望它對你有所幫助。

CATransition *animation = [CATransition animation]; 
    [animation setDelegate:self]; 
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]]; 
    [animation setDuration:0.8]; 
    [animation setType:kCATransitionFade]; 
    [animation setSubtype:kCATransitionMoveIn]; 

    //[[self.view layer]addAnimation:animation forKey:@"fview"]; 

    [self.navigationController.view.layer addAnimation:animation forKey:nil]; 

    [self.navigationController pushViewController:yourView animated:NO]; 

在動畫類型中,你可以給你想要的動畫。

希望能幫到你。

+0

無法看到動畫:( – Krunal

+0

我在我的項目中正在運行此代碼,請檢查它是否傳遞了正確的視圖名稱。如果您在代碼中推送視圖而不是子視圖,它會顯示動畫 – Manthan

+0

'RegistraionViewController * secondController = [[RegistraionViewController alloc] init]; CATransition * animation = [CATransition animation]; [animation setDelegate:self]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]]; [animation setDuration:0.8]; [animation setType:kCATransitionFade]; [animation setSubtype:kCATransitionMoveIn]; [self.navigationController.view.layer addAnimation:animation forKey:nil]; [self.navigationController pushViewController:secondController animated:NO];' – Krunal

0

*

- (IBAction)ClickMe:(id)sender { 
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init]; 
    CATransition *transitionAnimation = [CATransition animation]; 
    [transitionAnimation setDuration:1]; 
    [transitionAnimation setType:@"push"]; 
    [transitionAnimation setSubtype:kCATransitionFromBottom]; 
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; 
    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom]; 
    [self addChildViewController:secondController]; 
    [self.view addSubview:secondController.view]; 
} 

* 第1頁替換示例代碼:上述再檢查。

希望這對你有所幫助

相關問題