xcode 从一个视图控制器移动到另一个视图控制器的基于视图的应用程序中的从左到右转换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10845785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:27:36  来源:igfitidea点击:

left to right transition in view based application on moving from one view controller to another

iphoneobjective-ciosxcode

提问by Alok Srivastava

MyView *view=[[[MyView alloc] init] autorelease];
[view setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:view animated:YES];

I have used flip transition on moving from one view controller to another.but my requirement is from left to right transition. Please help me to way out this problem thanks in advance. here is my code:

我在从一个视图控制器移动到另一个视图控制器时使用了翻转过渡。但我的要求是从左到右过渡。请帮我解决这个问题,提前致谢。这是我的代码:

回答by Hector

You need to add QuartzCore Framework and then import #import <QuartzCore/QuartzCore.h>

您需要添加 QuartzCore Framework 然后导入 #import <QuartzCore/QuartzCore.h>

MyView *next = [[MyView alloc] init];
CATransition *animation = [CATransition animation];
[self presentModalViewController:next animated:NO];
[animation setDuration:0.40];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
//[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[next.view layer] addAnimation:animation forKey:@"SwitchToView1"];
[next release];

回答by Himanshu padia

I asume you are dismissing a view controller 2 from view controller 1. In view controller 2 you are using this

我假设您正在从视图控制器 1 中解除视图控制器 2。在视图控制器 2 中,您正在使用它

[self dismissModalViewControlleAnimated: NO];

[自我解雇ModalViewControlleAnimated:NO];

Now In the 1st view controller, import of "QuartzCore" header and add viewWillAppear method with code

现在在第一个视图控制器中,导入“QuartzCore”标头并使用代码添加 viewWillAppear 方法

#import <QuartzCore/QuartzCore.h>

(void)viewWillAppear:(BOOL)animated {

CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];

[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[self.view.layer addAnimation:animation forKey:kCATransition]; }

#import <QuartzCore/QuartzCore.h>

(无效)viewWillAppear:(BOOL)动画{

CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];

[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[self.view.layer addAnimation:animation forKey:kCATransition]; }

I hope this code will help you a lot.

我希望这段代码对你有很大帮助。

回答by shabbirv

Why don't you use a UINavigationControllerand push the UIViewControllerinstead of presenting it modally?

为什么不使用 aUINavigationController和 pushUIViewController代替模态呈现?

Edit:

编辑:

To change your view-based app into a UINavigationControllerjust add this to your AppDelegate

要将基于视图的应用程序更改为UINavigationController只需将此添加到您的 AppDelegate

    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    UINavigationController *nvcontrol = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    [self.window addSubview:nvcontrol.view];

回答by Son Nguyen

- (void)slideView:(UIView*)view direction:(BOOL)isLeftToRight {
    CGRect frame = view.frame;
    frame.origin.x = (isLeftToRight) ? -320 : 320;
    view.frame = frame;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    frame.origin.x = 0;
    view.frame = frame;
    [UIView commitAnimations];
}

回答by mAc

Yes, you should do this through Navigational Controller.

是的,你应该通过导航控制器来做到这一点。

Here is some code to help you, if you want to do it through Navigational Controller.

如果您想通过导航控制器执行此操作,这里有一些代码可以帮助您。

In AppDelegate.h:

在 AppDelegate.h 中:

@interface AppDelegate : UIResponder <UIApplicationDelegate,UINavigationControllerDelegate>{

    UINavigationController *navController;
}

In AppDelegate.m:

在 AppDelegate.m 中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // ViewController is your FirstViewController which loads over Window.

    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = _viewController;
    navController =[[UINavigationController alloc] initWithRootViewController:_viewController];
    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;
}

Then in your ViewController.m, in your button tapped function, you can do this:

然后在您的 ViewController.m 中,在点击按钮的功能中,您可以执行以下操作:

NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];

And that's all.

就这样。

回答by Saad

try this

尝试这个

[self.navigatationController pushViewController:view animated:YES];