3

我试图让我的 ViewController 以与标准 PushViewConrtoller 相同的速度从左滑到右,我没有使用 NavBar 也不想使用 Modal,有没有简单的方法可以做到这一点,我在不同的线程上看到了很多变化,但它们都不能正常工作!

我正在为我的 Push right 使用带有以下代码的导航控制器...

- (IBAction)launch1990:(id)sender {

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

3 回答 3

6

UIStroryBoard 当您推送视图控制器或 segues 时,它不会让您自定义太多。我最终做的是重写 perform 方法并使用 QuartzCore Animations 来自定义我们的过渡。我继承了 UIStoryBoardSegue 并覆盖了 perform 函数。

下面为 Push 或 Pop 定制,然后为 Segues 定制。(对于 segues,请记住将类更改为 IB 中的自定义类)。

要从普通的 pop 或 push(这确实交叉淡入淡出动画,请根据您的调整):

    #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
于 2013-02-27T16:25:38.037 回答
5

CATransition与_ subtype: kCATransitionFromLeft

CATransition *transition = [CATransition animation];
    transition.duration = .3;
    transition.type = kCATransitionMoveIn;
     transition.subtype= kCATransitionFromLeft;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
于 2013-02-27T16:49:26.303 回答
1

做正常的导航vc推送,但事先:

vc.navigationBar.hidden = YES;
于 2013-02-27T16:21:51.787 回答