2013-08-06 28 views
2

我正在从一个视图控制器导航到另一个视图控制器。为从一个类导航到另一个类有一个默认时间。我们可以通过编程方式更改该时间,即我们是否可以增加或减少导航速度。如何更改iOS SDK中的默认导航速度?

FlashScreen *Secreen=[[FlashScreen alloc]initWithNibName:nil bundle:nil]; 
    [self.navigationController pushViewController:Secreen animated:YES]; 
+1

你可以用动画来定制你的速度 –

+0

看到http://stackoverflow.com/questions/1406037/custom-animation-for-pushing-a-uiviewcontroller – Architect

+0

@Architect ...你给我的链接是使用“setAnimationTransition”。但我想要默认的动画,但速度不同。我试图使用setAnimationTransitionNone,然后直接进入下一个视图控制器没有任何动画,因为在推动我们设置动画“NO”.Any线索。 – Imran

回答

4
You need to use a custom animation like seague Animation class file where you can give the Transition duration for moving from one view controller to another view controller 

-(void)perform{ 
    UIViewController *sourceViewController = (UIViewController *) [self sourceViewController]; 
    UIViewController *destinationViewController = (UIViewController *) [self destinationViewController]; 
    CATransition* transition = [CATransition animation]; 
    if ([self.identifier isEqualToString:@"b"]){ 
     transition.duration = .25; 
     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
     transition.type = kCATransitionMoveIn; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade 
     transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom 
    }else{ 
     transition.duration = .25; 
     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
     transition.type = kCATransitionMoveIn; 
     transition.subtype = kCATransitionFromRight; 
    } 
    [sourceViewController.navigationController.view.layer addAnimation:transition 
                  forKey:kCATransition]; 
    [sourceViewController.navigationController pushViewController:destinationViewController animated:NO]; 
} 
+0

这就像一个魅力 – Ruban

+0

工作很好。感谢您的回应。 – Imran

1

你可以简单动画添加到任何类型的UIView的层。所以它会按照您的配置进行动画。

Reference of CALayer class

//Don't forgot to import QuartzCore framework in your project 
    #import <QuartzCore/QuartzCore.h> 

    #define ANIMATION_DURATION 6 

    /* Called when the animation begins its active duration. */ 
    - (void)animationDidStart:(CAAnimation *)anim{ 
     NSLog(@"animation start"); 
    } 

    /* Called when the animation either completes its active duration or 
    * is removed from the object it is attached to (i.e. the layer). 'flag' 
    * is true if the animation reached the end of its active duration 
    * without being removed. */ 

    - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ 
      NSLog(@"animation stop"); 
    } 

    -(void)PerformPushOnNavigationController{ 

     //Your view controller 
     UIViewController *yourViewController = [[UIViewController alloc] init]; 


     //Create a CATransition to add it in view layer 
     CATransition* TransitionFromRight = [CATransition animation]; 

     //Duration to animate 
     TransitionFromRight.duration = ANIMATION_DURATION; 

     //animation strategy to animate 
     TransitionFromRight.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 

     //we are going to simulate the push action of navigation controller, so here i am specifying transition type as push. Depends upon your needs of app behavior you can change it. 
     TransitionFromRight.type = kCATransitionPush; 

     /* 

     //type 

     NSString * const kCATransitionFade; 
     NSString * const kCATransitionMoveIn; 
     NSString * const kCATransitionPush; 
     NSString * const kCATransitionReveal; 

     */ 


     //Here we have subtype as kCATransitionFromRight which will do animate from right. For an example i would specify kCATransitionFromBottom to push view controller to navigation controller as modal controller. 
     TransitionFromRight.subtype = kCATransitionFromRight; 


     /* 

     //subtype 

     NSString * const kCATransitionFromRight; 
     NSString * const kCATransitionFromLeft; 
     NSString * const kCATransitionFromTop; 
     NSString * const kCATransitionFromBottom; 

     */ 

     //set the CAAnimation delegate to self, so that it will notify you when start and stop the animation 
     //Optional, If you want to do something before/after animation, use the delegate. 
     //Note that CAAnimation delegate will be retained. 
     //So be carefull when you use this on POP simulation.In ARC No issues. Non ARC should take care of it. 
     TransitionFromRight.delegate = self; 

     //Add animation to the navigation controller's view's layer 
     [self.navigationController.view.layer addAnimation:TransitionFromRight forKey:nil]; 

     //Finally you push viewcontroller to your navigation controller. 
     [self.navigationController pushViewController:yourViewController animated:NO]; 



    }