2014-10-17 2 views

ответ

2

Вы «нажимаете» контроллер вида на стек навигационной панели. Но когда вы представляете контроллер вида без контроллера навигации, вы называете его «настоящим» (а не «push»). Означает, что термин «толкание» контроллера просмотра вряд ли подключен к UINavigationController.

Таким образом, вы можете просто использовать Google для чего-то вроде «пользовательского перехода UIViewController» или чего-то подобного.

I did great success following a this great article by Teehan+Lax. Просто прочитайте его, это должно привести вас к правильному пути.

EDIT Хорошо. Я собираюсь добавить некоторую информацию, чтобы дать вам лучший ответ.

Прежде всего, вы будете создавать новый подкласс NSObject и соответствовать UIViewControllerAnimatedTransitioning протокола:

@interface JWTransitionAnimator <UIViewControllerAnimatedTransitioning> 
+ (JWTransitionAnimator *)transitionAnimatorForPresentation; 
+ (JWTransitionAnimator *)transitionAnimatorForDismissal; 
@end 

Затем пусть волшебство произойдет в вашей реализации:

@interface JWTransitionAnimator() 
@property (atomic, assign, getter=isPresenting) BOOL presenting; 
@end 

@implementation JWTransitionAnimator 
+ (JWTransitionAnimator *)transitionAnimatorForPresentation { 
    JWTransitionAnimator *animator = [[self alloc] init]; 
    [animator setPresenting:YES]; 

    return animator; 
} 
+ (JWTransitionAnimator *)transitionAnimatorForDismissal { 
    return [[self alloc] init]; 
} 

// implement the protocol: 
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitioningContext { 
    return 0.3; // or any other duration. 
} 
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitioningContext { 
    UIViewController *fromViewController = [transitioningContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *toViewController = [transitionContext UITransitionContextToViewController]; 

    UIView *fromView = [fromViewController view]; 
    UIView *toView = [toViewController view]; 

    if ([self isPresenting]) { 
     [fromView setUserInteractionEnabled:NO]; 

     [[transitionContext containerView] addSubview:fromView]; 
     [[transitionContext containerView] addSubview:toView]; 

     [toView setAlpha:0.0]; 
     [toView setTransform:CGAffineTransformScale([fromView transform], 0.3, 0.3)]; 

     [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ 
      [fromView setTintAdjustmentMode:UIViewTintAdjustmentModeDimmed]; 

      [toView setAlpha:1.0]; 
      [toView setTransform:CGAffineTransformScale([toView transform], 1.0, 1.0)]; 
     } completion:^(BOOL finished) { 
      [transitionContext completeTransition:finished]; 
     }]; 
    } 
    else { 
     // reverse your animation here (change "fromView" for "toView" and vice-versa) 
    } 
} 

Ваш предлежащей viewController должен соответствовать протоколу UIViewControllerTransitionDelegate. Реализовать его следующим образом:

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { 
    return [JWTransitionAnimator transitionAnimatorForPresentation]; 
} 
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { 
    return [JWTransitionAnimator transitionAnimatorForDismissal]; 
} 

вы представить контроллер представления, как это:

- (IBAction)presentViewController:(id)sender { 
    UIViewController *yourVC = [[UIViewController alloc] init]; // however you create it 
    [yourVC setModalPresentationStyle:UIModalPresentationStyleCustom]; 
    [yourVC setTransitionDelegate:self]; 

    [self presentViewController:yourVC animated:YES completion:NULL]; 
} 
Смежные вопросы