我正在尝试使ViewController以与标准PushViewConrtoller相同的速度从左向右滑动,我没有使用NavBar,也不想使用Modal,是否有一种简单的方法来做到这一点,我我们已经在不同的线程上看到了很多变化,但是没有一个能正常工作!

我正在使用带有以下代码的导航控制器进行“向右推”操作...

- (IBAction)launch1990:(id)sender {

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"1990"];
[self.navigationController pushViewController:vc animated:YES];
}

最佳答案

当按下视图控制器或segue时,UIStroryBoard不会让您自定义太多。我最终要做的是重写perform方法,并使用QuartzCore Animations自定义过渡。我将UIStoryBoardSegue子类化,并重写了perform函数。

在下面针对推送或流行然后针对Segues进行定制。 (对于segues,请记住在IB中将类更改为自定义类)。

要通过正常的弹出或推动操作来完成此操作(这会产生淡入淡出的动画效果,请根据自己的喜好进行调整):

    #import <QuartzCore/QuartzCore.h>


 - (IBAction)launch1990:(id)sender {
    CATransition* transition = [CATransition animation];
    transition.duration = .45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"1990Storyboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"1990"];
    [self.navigationController pushViewController:vc animated:NO];
  }


要通过segue做到这一点:

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

@interface ZHCustomSegue : UIStoryboardSegue

@end


//  ZHCustomSegue.m
#import "ZHCustomSegue.h"
#import "QuartzCore/QuartzCore.h"

@implementation ZHCustomSegue


-(void)perform {

    UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
    UIViewController *destinationController = (UIViewController*)[self destinationViewController];

    CATransition* transition = [CATransition animation];
    transition.duration = .45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush,   kCATransitionReveal, kCATransitionFade
   //transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom



    [sourceViewController.navigationController.view.layer addAnimation:transition
                                                            forKey:kCATransition];

    [sourceViewController.navigationController pushViewController:destinationController animated:NO];

}
@end

07-28 02:31