MyView *view=[[[MyView alloc] init] autorelease];
[view setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:view animated:YES];
我在从一个视图控制器移动到另一个视图控制器时使用了翻转过渡。但我的要求是从左到右过渡。请帮我解决这个问题,谢谢。这是我的代码:
MyView *view=[[[MyView alloc] init] autorelease];
[view setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:view animated:YES];
我在从一个视图控制器移动到另一个视图控制器时使用了翻转过渡。但我的要求是从左到右过渡。请帮我解决这个问题,谢谢。这是我的代码:
您需要添加 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];
我假设您正在从视图控制器 1 中关闭视图控制器 2。在视图控制器 2 中,您正在使用它
[self dismissModalViewControlleAnimated: NO];
现在在第一个视图控制器中,导入“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];
}
你为什么不使用 aUINavigationController
和 pushUIViewController
而不是以模态方式呈现它?
编辑:
要将基于视图的应用程序更改为UINavigationController
只需将其添加到您的 AppDelegate
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nvcontrol = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:nvcontrol.view];
- (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];
}
是的,您应该通过导航控制器执行此操作。
如果您想通过导航控制器执行此操作,这里有一些代码可以帮助您。
在 AppDelegate.h 中:
@interface AppDelegate : UIResponder <UIApplicationDelegate,UINavigationControllerDelegate>{
UINavigationController *navController;
}
在 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;
}
然后在您的 ViewController.m 中,在您的按钮点击功能中,您可以执行以下操作:
NextViewController *nextController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
[self.navigationController pushViewController:nextController animated:YES];
就这样。
试试这个
[self.navigatationController pushViewController:view animated:YES];