Implementing delegate methods in separate class

195 views Asked by At

I created delegate and its methods are the same to every VC that it supports. How can I use with out code duplication?

My code

#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

There are 2 answers

2
rounak On BEST ANSWER

You can use a separate class dedicated to the delegate methods, or use a view controller subclass, which every other VC will inherit from.

1
Clement Prem On

As @rounak suggests you can create a separate class dedicated for handling the delegation.

Example

Create an NSObject subclass and adopt UIViewControllerTransitioningDelegate and add & implement the delegate methods.

In you VC assign your new object as the transitioningDelegate