dany dany - 5 months ago 15
Objective-C Question

how to create function for this code in objective c

I had written transition animation code for

UIView
but this code is use in multiple screen so all the time I am writing the same code but I want to create class or function so I can easily call this wherever required but I am new in iOS so please help me how to create function and calling in
UIView
..

CATransition *trans = [CATransition animation];
trans.duration = 0.5;
trans.type = kCATransitionPush;
trans.subtype = kCATransitionFromTop;
[trans setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[self.container_view.layer trans forKey:nil];


thanks in advance

Answer

Create AppFunction class like this:

1. Header File

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface AppFunctions : NSObject
    + (void) animateView:(UIView *)view;
@end

2. Implementation File

#import "AppFunctions.h"

@implementation AppFunctions
+ (void) animateView:(UIView *) view
{
  CATransition *trans = [CATransition animation];
  trans.duration = 0.5;
  trans.type = kCATransitionPush;
  trans.subtype = kCATransitionFromTop;
  [trans setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

  [view.layer addAnimation:trans forKey:nil];
}
@end

Now call Like this where you want by importing #import "AppFunctions.h"

[AppFunctions animateView:self.view];