ios navigationcontroller 使用,以及自定义动画切换特效CATransi...
2012-11-14 22:26
483 查看
1:正常建立工程
2:新建一个objective-C类,命名(可以随便)RootViewController,可带可不带xib文件
3:appdelegate.h
4:appdelegate.m
RootViewController.m
2:新建一个objective-C类,命名(可以随便)RootViewController,可带可不带xib文件
3:appdelegate.h
#import <UIKit/UIKit.h> @class RootViewController; @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) RootViewController *rootviewcontroller; //实的 @property (strong,nonatomic) UINavigationController *navigationController; //虚的 @end
4:appdelegate.m
#import "AppDelegate.h" #import "RootViewController.h" @implementation AppDelegate @synthesize window = _window; @synthesize rootviewcontroller = _rootviewcontroller; @synthesize navigationController; - (void)dealloc { [_window release]; [_rootviewcontroller release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //代码添加navagationController // self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // // Override point for customization after application launch. // self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; // UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; // // [self.window addSubview:navController.view]; // self.window.rootViewController = navController; // //self.window.rootViewController = self.viewController; // [self.window makeKeyAndVisible]; // return YES; // self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. [self.window makeKeyAndVisible]; self.rootviewcontroller = [[RootViewController alloc] initWithNibName:Nil bundle:NULL]; self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootviewcontroller]; [self.window addSubview:navigationController.view]; return YES; }
RootViewController.m
// // RootViewController.m // Qin // // Created by jstv.com jstv on 12-6-11. // Copyright (c) 2012年 jstv.com. All rights reserved. // #import "RootViewController.h" #import "MapViewController.h" #import <QuartzCore/QuartzCore.h> @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; //定制navagationbar //右边添加一个按钮 // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStyleBordered target:self action:@selector(nav1_do)]; // self.navigationItem.rightBarButtonItem = item1; // [item1 release]; //右边添加多个按钮 UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 45)]; [toolbar setTintColor:[self.navigationController.navigationBar tintColor]]; [toolbar setAlpha:[self.navigationController.navigationBar alpha]]; NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2]; //Capacity,容量 UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithTitle:@"btn1title" style:UIBarButtonItemStyleBordered target:self action:@selector(btn1_do)]; UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithTitle:@"btn2title" style:UIBarButtonItemStyleBordered target:self action:@selector(btn2_do)]; [buttons addObject:btn1]; [btn1 release]; [buttons addObject:btn2]; [btn2 release]; [toolbar setItems:buttons animated:YES]; [buttons release]; UIBarButtonItem *myitem = [[UIBarButtonItem alloc] initWithCustomView:toolbar]; self.navigationItem.rightBarButtonItem = myitem; [myitem release]; [toolbar release]; [self setTitle:@"Page One"]; NSLog(@"来到了rootviewcontroller"); [self.navigationController setNavigationBarHidden:YES]; // Do any additional setup after loading the view from its nib. } -(void)nav1_do { MapViewController *mapview = [[MapViewController alloc] initWithNibName:Nil bundle:NULL]; //[self.navigationController pushViewController:mapview animated:YES]; //[self.navigationController popToViewController:mapview animated:YES]; [self.navigationController presentModalViewController:mapview animated:YES]; //从下往上弹出 } -(void)btn1_do { NSLog(@"btn1_do"); MapViewController *mapview = [[MapViewController alloc] initWithNibName:Nil bundle:NULL]; [self.navigationController pushViewController:mapview animated:YES]; } -(void)btn2_do { NSLog(@"btn2_do"); } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (IBAction)goMapview { //presentModalViewController切换 MapViewController *mapview = [[MapViewController alloc] initWithNibName:Nil bundle:NULL]; [self.navigationController presentModalViewController:mapview animated:YES]; } - (IBAction)CustomPushview { //自定义切换动画效果 CATransition *animation = [CATransition animation]; [animation setDuration:3.3]; [animation setType:kCATransitionFade]; //淡入淡出 [animation setSubtype:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; MapViewController *mapview = [[MapViewController alloc] initWithNibName:Nil bundle:NULL]; [self.navigationController pushViewController:mapview animated:NO]; [self.navigationController.view.layer addAnimation:animation forKey:nil]; } @end
相关文章推荐
- 【iOS学习笔记 15-11-06】简单自定义navigationcontroller push和pop动画效果
- IOS ViewController切换动画以及如何返回
- iOS动画和特效(四)controller间的自定义过渡效果
- iOS动画和特效(四)controller间的自定义过渡效果
- iOS开发之使用画板和CA自定义有动画效果的AlertView
- iOS:更改navigationController push和pop界面切换动画
- Android使用多个Acitvity切换页面的方法_以及切入的动画效果
- iOS_20_微博自定义可动画切换的导航控制器
- 使用属性动画以及自定义view实现图片的显示与隐藏
- iOS 7:自定义导航转场动画以及更多
- iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
- iOS中使用自定义ttf/ttc字体,以及cocosbuilder中指定字体的方法
- 自定义viewController切换动画
- iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
- 自定义viewController的present切换动画
- 【iOS-Cocos2d游戏开发之二十一 】自定义精灵类并为你的精灵设置攻击帧以及动画创建!【一】
- iOS 自定义转场动画实现小红书的push效果思路以及下雪碎屏等动画的实现
- [Android]Fragment自定义动画、动画监听以及兼容性包使用 - Ginsan
- Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS
- iOS开发-自定义TabBar使用popToRootViewControllerAnimated重叠问题解决