Tengo una aplicación con NavigationController. ¿Cómo puedo cambiar la animación de transición estilo de pushViewController y popToViewController?

UPD

He creado la categoría como en @lawicko respuesta. Pero tengo un error cuando estoy tratando de llamar a la función

[auto.navigationController pushViewController:lugares withCustomTransition:CustomViewAnimationTransitionPush subtipo:CustomViewAnimationSubtypeFromLeft];

error es : «el uso de identificador no declarado ‘CustomViewAnimationTransitionPush'»

Donde debo declarar esta parte:

typedef enum {
    CustomViewAnimationTransitionNone,
    CustomViewAnimationTransitionFlipFromLeft,
    CustomViewAnimationTransitionFlipFromRight,
    CustomViewAnimationTransitionCurlUp,
    CustomViewAnimationTransitionCurlDown,
    CustomViewAnimationTransitionFadeIn,
    CustomViewAnimationTransitionMoveIn,
    CustomViewAnimationTransitionPush,
    CustomViewAnimationTransitionReveal
} CustomViewAnimationTransition;

Escribir ahora lo declaro en UINavigationController+Additions.h

UPD 2: Un nuevo error:

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_CATransition", referenced from:
      objc-class-ref in UINavigationController+Additions.o
  "_kCATransition", referenced from:

y los mismos errores de celebrar todos los _kCATransitions

Intenta esto? [1]: stackoverflow.com/questions/3699882/…
eso es ok, pero quiero animación como en el botón atrás.. pero establecer que para pushViewController
Yo realmente no lo entiendo. Desea que la animación que usted tiene cuando usted haga clic en back (popViewController) a ser uno de los que cuando se presione la vista (pushViewController)?
sí! quiero animación como deslizamiento horizontal. pero con dirección a la izquierda

OriginalEl autor Eugene Trapeznikov | 2012-02-28

3 Comentarios

  1. 19

    Echa un vistazo a este UINavigationController categoría que he creado. Se permite empujar y apareciendo con bastante cada posible transición, y también es compatible con los subtipos de QuartzCore transiciones, lo que le permitirá hacer exactamente lo que quieres – empuje el punto de vista de la izquierda. Hacerlo así:

    [self.navigationController pushViewController:[[MyController alloc] init] withCustomTransition:CustomViewAnimationTransitionPush subtype:CustomViewAnimationSubtypeFromLeft];

    El código que está a continuación. La primera parte que usted necesita para poner en la parte de encabezado:

    //IMPORTANT - basic transitions like flip and curl are local, they reside only in animation block. Core animations however,
    //once assigned to the layer, stay until changed or reset (by assigning nil as layer animation property)
    
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import <QuartzCore/QuartzCore.h>
    
    typedef enum {
        CustomViewAnimationTransitionNone,
        CustomViewAnimationTransitionFlipFromLeft,
        CustomViewAnimationTransitionFlipFromRight,
        CustomViewAnimationTransitionCurlUp,
        CustomViewAnimationTransitionCurlDown,
        CustomViewAnimationTransitionFadeIn,
        CustomViewAnimationTransitionMoveIn,
        CustomViewAnimationTransitionPush,
        CustomViewAnimationTransitionReveal
    } CustomViewAnimationTransition;
    
    #define CustomViewAnimationSubtypeFromRight kCATransitionFromRight
    #define CustomViewAnimationSubtypeFromLeft kCATransitionFromLeft
    #define CustomViewAnimationSubtypeFromTop kCATransitionFromTop
    #define CustomViewAnimationSubtypeFromBottom kCATransitionFromBottom
    
    @interface UINavigationController(Additions)
    
    - (void)pushViewController:(UIViewController *)viewController withCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype;
    
    - (void)popViewControllerWithCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype;
    - (void)popToRootViewControllerWithCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype;
    - (void)popToViewController:(UIViewController *)viewController withCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype;
    
    @end

    Esta segunda parte que usted necesita para poner en el archivo de implementación:

    #import "UINavigationController_Additions.h"
    @interface UINavigationController()
    - (void)standardAnimationWithController:(UIViewController*)viewController
    duration:(NSTimeInterval)duration
    options:(UIViewAnimationOptions)options
    changesBlock:(void (^)(void))block;
    - (void)coreAnimationWithController:(UIViewController*)viewController
    duration:(NSTimeInterval)duration
    type:(NSString*)type
    subtype:(NSString*)subtype
    changesBlock:(void (^)(void))block;
    @end
    @implementation UINavigationController(Additions)
    #pragma mark -
    #pragma mark pushing
    - (void)pushViewController:(UIViewController *)viewController withCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype {
    switch (transition) {
    case CustomViewAnimationTransitionNone:{
    [self standardAnimationWithController:viewController duration:.5 options:UIViewAnimationOptionTransitionNone
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromLeft:{
    [self standardAnimationWithController:viewController duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromRight:{
    [self standardAnimationWithController:viewController duration:.5 options:UIViewAnimationOptionTransitionFlipFromRight
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlUp:{
    [self standardAnimationWithController:viewController duration:.5 options:UIViewAnimationOptionTransitionCurlUp
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlDown:{
    [self standardAnimationWithController:viewController duration:.5 options:UIViewAnimationOptionTransitionCurlDown
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFadeIn:{
    [self coreAnimationWithController:viewController duration:.5 type:kCATransitionFade subtype:nil
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionMoveIn:{
    [self coreAnimationWithController:viewController duration:.5 type:kCATransitionMoveIn subtype:subtype
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionPush:{
    [self coreAnimationWithController:viewController duration:.5 type:kCATransitionPush subtype:subtype
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionReveal:{
    [self coreAnimationWithController:viewController duration:.5 type:kCATransitionReveal subtype:subtype
    changesBlock:^{
    [self pushViewController:viewController animated:NO];
    }];
    break;}
    default:{
    break;}
    }
    }
    #pragma mark -
    #pragma mark popping
    - (void)popViewControllerWithCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype {
    switch (transition) {
    case CustomViewAnimationTransitionNone:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionNone
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromLeft:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromRight:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionFlipFromRight
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlUp:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionCurlUp
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlDown:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionCurlDown
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFadeIn:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionFade subtype:nil
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionMoveIn:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionMoveIn subtype:subtype
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionPush:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionPush subtype:subtype
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionReveal:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionReveal subtype:subtype
    changesBlock:^{
    [self popViewControllerAnimated:NO];
    }];
    break;}
    default:{
    break;}
    }
    }
    - (void)popToRootViewControllerWithCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype {
    switch (transition) {
    case CustomViewAnimationTransitionNone:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionNone
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromLeft:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromRight:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionFlipFromRight
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlUp:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionCurlUp
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlDown:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionCurlDown
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFadeIn:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionFade subtype:nil
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionMoveIn:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionMoveIn subtype:subtype
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionPush:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionPush subtype:subtype
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionReveal:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionReveal subtype:subtype
    changesBlock:^{
    [self popToRootViewControllerAnimated:NO];
    }];
    break;}
    default:{
    break;}
    }    
    }
    - (void)popToViewController:(UIViewController *)viewController withCustomTransition:(CustomViewAnimationTransition)transition subtype:(NSString*)subtype {
    switch (transition) {
    case CustomViewAnimationTransitionNone:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionNone
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromLeft:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionFlipFromLeft
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFlipFromRight:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionFlipFromRight
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlUp:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionCurlUp
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionCurlDown:{
    [self standardAnimationWithController:nil duration:.5 options:UIViewAnimationOptionTransitionCurlDown
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionFadeIn:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionFade subtype:nil
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionMoveIn:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionMoveIn subtype:subtype
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionPush:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionPush subtype:subtype
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    case CustomViewAnimationTransitionReveal:{
    [self coreAnimationWithController:nil duration:.5 type:kCATransitionReveal subtype:subtype
    changesBlock:^{
    [self popToViewController:viewController animated:NO];
    }];
    break;}
    default:{
    break;}
    }        
    }
    #pragma mark -
    #pragma mark private
    - (void)standardAnimationWithController:(UIViewController*)viewController
    duration:(NSTimeInterval)duration
    options:(UIViewAnimationOptions)options
    changesBlock:(void (^)(void))block {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    [UIView transitionWithView:self.view duration:duration options:options animations:block completion:NULL];
    [UIView commitAnimations];
    }
    - (void)coreAnimationWithController:(UIViewController*)viewController
    duration:(NSTimeInterval)duration
    type:(NSString*)type
    subtype:(NSString*)subtype
    changesBlock:(void (^)(void))block {
    CATransition* trans = [CATransition animation];
    [trans setDuration:duration];
    [trans setType:type];
    [trans setSubtype:subtype];
    [self.view.layer addAnimation:trans forKey:kCATransition];
    block();
    }
    @end
    oh! debo incluir a mi costumbre NavigationController?
    Nope, sólo pega este código en los archivos de la categoría (.h para la interfaz .m para la implementación) y asegurarse de que estén disponibles en su proyecto. A continuación, importar el archivo de encabezado dondequiera que usted desea utilizar la categoría de método. Si usted está teniendo problemas para entender cómo la categoría de obras consulte aquí.
    creo categoría.. pero hay un error. por favor, mire upd
    He dividido el código en dos, sólo tienes que pegar la primera parte en el encabezado y el segundo en el archivo de implementación.
    yo lo hice en la forma en que usted habla. puede ser el problema en algunas otras razones

    OriginalEl autor lawicko

  2. 2

    Necesita agregar QuartzCore.framework a su destino a resolver _OBJC_CLASS_$_CATransition error.

    OriginalEl autor fannheyward

  3. 0

    Recientemente he abordado la creación de mi propia transición, aquí está la biblioteca reutilizable que yo hice:

    https://github.com/travisjeffery/TRVSNavigationControllerTransition

    Y aquí está mi blog hablando acerca de cómo hacer su propia transición.

    La idea básica es bastante simple, aunque, acaba de tomar una CALayer instantánea de la navigationController s (actual) de la vista, entonces push/pop de la vista sin animación, tomar un CALayer instantánea de la nueva vista y, a continuación, añadir tus propias animaciones para las capas y, a continuación, quitar las capas una vez que la animación se ha completado.

    Tomar la instantánea en serio retrasos en la transición. Sobre todo en los dispositivos más antiguos.
    iOS 7 tiene un método para hacer esto es especialmente rápido ahora…

    OriginalEl autor travisjeffery

Dejar respuesta

Please enter your comment!
Please enter your name here