2013-07-22 52 views
3

我想在我的viewControllers之間創建一個自定義的過渡。我遵循this教程,但點擊/點擊按鈕後沒有任何反應!CATransition的自定義塞格不工作

這是CustomSegue.m

#import "CustomSegue.h" 
#import "QuartzCore/QuartzCore.h" 

@implementation CustomSegue 

-(void)perform { 
NSLog(@"ActionTest"); 

UIViewController *sourceViewController = (UIViewController*)[self sourceViewController]; 
UIViewController *destinationController = (UIViewController*)[self destinationViewController]; 

CATransition* transition = [CATransition animation]; 
transition.duration = .25; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade 
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom 



[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition]; 
[sourceViewController.navigationController pushViewController:destinationController animated:NO]; 
} 

@end 

的日誌中記錄的代碼,但不進行轉變,也不是視圖 - 控制的變化。 我也改變了塞格風格「定製」和類到「ZHCustomSegue」

我錯過了什麼嗎?

謝謝

+0

你能在故事板上分享你的自定義segue的截圖嗎?您可以使用⌘+4 – Can

+0

您是否已將故事板文件中的segue類型更改爲ZHCustomSegue? –

+0

@可以,不幸的是我需要10個聲望才能在這裏上傳圖片,所以這裏是圖片的鏈接:http://s13.postimg.org/8pgyvfhl3/Screen_Shot_2013_07_22_at_10_41_57_AM.png –

回答

4

更改您的賽格瑞的最後兩行這樣的:

[destinationViewController.view.layer addAnimation:transition forKey:kCATransition]; 
[sourceViewController presentViewController:destinationController animated:NO completion:nil]; 

你試圖引用一個導航控制器,這是不存在的。

+0

原來的關鍵是在kCATransition – Andy