2015-06-10 42 views
0

我創建的委託及其方法與其支持的每個VC都相同。我如何使用代碼重複?在單獨的類中實現委託方法

我的代碼

的#pragma馬克 - UIViewControllerTransitioningDelegate

(id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source 
{ 
CircularTransitionAnimator *animator = [CircularTransitionAnimator new]; 
animator.isPresenting = YES; 
self.pointForAnimationOfViewUserPhotos = point; 
animator.actionPoint = point; 
return animator; 
} 

-(id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed 
{ 
CircularTransitionAnimator *animator = [CircularTransitionAnimator new]; 
animator.isPresenting = NO; 
animator.actionPoint = self.pointForAnimationOfViewUserPhotos; 
return animator; 

}

回答

0

您可以使用專用的委託方法一個單獨的類,或使用視圖控制器子類,其他每個VC都將繼承。

+0

我該怎麼辦第一種情況?第二個我明白 –

+0

只需創建一個新的NSObject子類,讓它實現這些方法。在每個VC中對該類進行實例化,並將其指定爲委託。 – rounak

0

由於@rounak建議您可以創建一個專門用於處理委派的單獨類。

創建一個NSObject的子類,並採取UIViewControllerTransitioningDelegate並添加&實現委託方法。

在你的VC分配新對象爲transitioningDelegate

+0

我需要類的方法實現 –

+0

檢查我的編輯...它是否回答你的問題? –

+0

是的,謝謝,@rounak回答完美 –