gpt4 book ai didi

iphone - 将ViewController推到左边-简单吗?

转载 作者:行者123 更新时间:2023-12-03 19:29:21 25 4
gpt4 key购买 nike

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

我正在使用带有以下代码的导航 Controller 来实现右推...

- (IBAction)launch1990:(id)sender {

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

最佳答案

UIStroryBoard 当您推送 View Controller 或 segues 时,它不允许您自定义太多。我最终做的是覆盖执行方法并使用 QuartzCore 动画来自定义我们的转换。我对 UIStoryBoardSegue 进行了子类化并覆盖了执行函数。

下面自定义 Push 或 Pop,然后自定义 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

关于iphone - 将ViewController推到左边-简单吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15116801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com