标签:
// 创建UIWindow对象 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 设置背景颜色 self.window.backgroundColor = [UIColor whiteColor]; // 使window显示 [self.window makeKeyAndVisible]; // 创建视图控制器,给window指定根控制器,设置导航控制器 self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor brownColor]; // 设置导航控制器 [self initLayout]; } // 初始化布局(实现布局的方法) - (void)initLayout { // 导航控制器的显示隐藏属性(YES == 隐藏, NO == 显示) self.navigationController.navigationBarHidden = NO; // UINavigationBar(导航条,iOS7.0 之后导航条默认有半透明属性) // 设置导航条是否开启半透明效果(会影响self.subViews的坐标系,当半透明效果开启时,self.view以屏幕左上角为坐标原点,关闭时,导航条左下角为坐标原点) self.navigationController.navigationBar.translucent = NO; // 修改导航条颜色,状态栏颜色默认与导航条颜色相同 self.navigationController.navigationBar.barTintColor = [UIColor grayColor]; // 导航条背景颜色 self.navigationController.navigationBar.backgroundColor = [UIColor redColor]; // 设置导航条标题 // self.title = @"根视图"; // navigationItem属性,用来设置子控件 self.navigationItem.title = @"根视图"; // 左按钮 self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"左按钮" style:UIBarButtonItemStylePlain target:self action:@selector(leftItemAciton:)]; // 右按钮 // 一个按钮 // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(rightItemClick:)]; // // self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"next"] style:UIBarButtonItemStylePlain target:self action:@selector(rightItemClick:)]; // 多个按钮, 自动排序 UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(rightItemClick:)]; UIBarButtonItem *item2 =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(rightItemClick:)]; self.navigationItem.rightBarButtonItems = @[item2, item1]; // 设置导航元素的颜色 self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; // 导航栏样式 self.navigationController.navigationBar.barStyle = UIBarStyleBlack; // 标题视图 UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"男神", @"女神", @"-1"]]; segment.frame = CGRectMake(0, 0, 150, 30); segment.selectedSegmentIndex = 0; [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged]; self.navigationItem.titleView = segment; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; view.backgroundColor = [UIColor lightGrayColor]; [self.view addSubview:view]; } // 实现左按钮方法 - (void)leftItemAciton:(UIBarButtonItem *)sender { NSLog(@"跟着我左手 慢动作"); } - (void)segmentAction:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) { case 0: self.view.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1]; break; case 1: self.view.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:1]; break; case 2: self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:1]; break; default: break; } } // 实现右按钮方法 - (void)rightItemClick:(UIBarButtonItem *)sender { NSLog(@"跟着我右手 慢动作重播"); } @end
// 实现按钮方法 - (void)btnAction:(UIButton *)sender { // 创建第一页的对象 FirstViewController *fVC = [[FirstViewController alloc] init]; // 通过导航控制器推出新的页面 [self.navigationController pushViewController:fVC animated:YES]; }
- (void)popButtonAction:(UIButton *)sender { // 返回上一个视图 [self.navigationController popViewControllerAnimated:YES]; // 返回指定视图 [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES]; // 返回根视图 [self.navigationController popToRootViewControllerAnimated:YES]; }
- (void)modelBtnAction:(UIButton *)sender { // 创建第二页对象 ShowViewController *sVC = [[ShowViewController alloc] init]; // 给第二页设置导航控制器 UINavigationController *sNVC = [[UINavigationController alloc] initWithRootViewController:sVC]; // 添加模态动画 sVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical; // 模态跳到下一个页面 [self.navigationController presentViewController:sNVC animated:YES completion:nil]; }
- (void)backBtnAction:(UIButton *)sender { // 模态返回上一个视图 [self dismissViewControllerAnimated:YES completion:nil]; }
// 模态动画的效果
// UIModalTransitionStylePartialCurl 翻页方式 推出 // UIModalTransitionStyleFlipHorizontal 水平旋转方式 推出 // UIModalTransitionStyleCrossDissolve 交叉叠化溶解方式 推出 // UIModalTransitionStyleCoverVertical 垂直覆盖方式 推出
标签:
原文地址:http://www.cnblogs.com/soley/p/5398373.html