2016-06-22 9 views
3

Ich hatte Übergang Animationscode für UIView geschrieben, aber dieser Code ist in mehreren Bildschirm verwenden, so dass ich die ganze Zeit den gleichen Code schreibe aber ich möchte Klasse oder Funktion erstellen, damit ich kann leicht nennen dies wo immer erforderlich, aber ich bin neu in iOS so bitte helfen Sie mir, wie Funktion erstellen und in UIView ..wie man Funktion für diesen Code in Ziel c

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]; 

dank im Voraus

+0

wollen, sollten Sie auch prüfen, es zu einer Kategorie hinzufügen, wenn Sie es jederzeit verwenden. – Joshua

Antwort

3

erstellen AppFunction Klasse wie folgt:

1. Header-Datei

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

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

2. Implementierungsdatei

#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 

Rufen Sie nun das Beispiel, wo Sie durch den Import #import "AppFunctions.h"

[AppFunctions animateView:self.view]; 
1

nennen diese Methode wie diese

Aufruf

hier ist Ihre funcation

-(void)animate:(UIView *)view{ 
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];} 
+0

aber ich habe eine Mehrfachansicht – dany

+0

Sie müssen nur diese Datei auf jeder Seite importieren, wo Sie diese Funktion verwenden möchten – PinkeshGjr

+0

wie diese #import "youfunction.h" und dann diese Funktion wie folgt aufrufen [youncation animate: self.view] ; – PinkeshGjr