在单独的类中实现委托方法

时间:2015-06-10 11:53:53

标签: ios iphone uiviewcontroller delegates

我创建了委托,它的方法与它支持的每个VC都是一样的。如何使用代码重复?

我的代码

#pragma mark - 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;

}

2 个答案:

答案 0 :(得分:0)

您可以使用专用于委托方法的单独类,或使用视图控制器子类,每个其他VC都将从该子类继承。

答案 1 :(得分:0)

正如@rounak建议您可以创建一个专门用于处理委派的单独类。

实施例

创建一个NSObject子类并采用UIViewControllerTransitioningDelegate并添加&amp;实现委托方法。

在VC中,您将新对象指定为transitioningDelegate