Navigation + Tab Bar 常用组合框架

简介:

        

看到很多项目中都采用的是Navigation加Tab Bar组合到一起,完成视图切换操作,在导航栏上添加基本按钮,给予响应时间,让应用给用户更好的体验,所以本菜鸟写了这个这样一个Demo,仅供学习


所创建工程模板是最后一个 Empty Application

      

先看运行效果:


第一个视图,点击按钮切换视图,点击导航栏上按钮可以切换回去

     


第二个视图设置了背景颜色和透明度  第三个视图添加了背景图片


    


第四个视图,在导航栏上添加了两个按钮,左边按钮属于自定义标题,右边按钮是系统的图标,点击左按钮弹出一个警告,右边按钮没有添加响应事件,点击后没反应


     


Tab Bar上添加的都是自定义图片


框架组合的主要代码,在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];     // Override point for customization after application launch.     self.window.backgroundColor = [UIColor whiteColor];          _tabBarController = [[UITabBarController alloc] init];     _tabBarController.delegate = self;           FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];          SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];          ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];          FourViewController *fourViewController = [[FourViewController alloc] initWithNibName:@"FourViewController" bundle:nil];          UINavigationController *navFirst = [[UINavigationController alloc] initWithRootViewController:firstViewController]; //    在加载图片是把标题都覆盖了,所以运行效果并没有显示这些文字     navFirst.title = @"第一个视图";          UINavigationController *navSecond = [[UINavigationController alloc] initWithRootViewController:secondViewController];     navSecond.title = @"第二个视图";          UINavigationController *navThird = [[UINavigationController alloc] initWithRootViewController:thirdViewController];     navThird.title = @"第三个视图";          UINavigationController *navFour = [[UINavigationController alloc] initWithRootViewController:fourViewController];     navFour.title = @"第四个视图";               _tabBarController.viewControllers = [NSArray arrayWithObjects:navFirst,navSecond,navThird,navFour, nil];     _window.rootViewController = _tabBarController;          [self.window addSubview:firstViewController.view];     [self.window makeKeyAndVisible];     return YES; } 

第一个视图切换按钮响应事件

- (IBAction)switchView:(id)sender {          FirstViewController *firstController = [[FirstViewController alloc] init];     [self.navigationController pushViewController:firstController animated:YES];     firstController.title = @"第一个视图另一个视图"; } 

第四个视图添加两个按钮方法,在最后一个控制机的.m文件中的-(void)viewDidLoad方法中


- (void)viewDidLoad {     [super viewDidLoad]; 	// Do any additional setup after loading the view.     UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"测试"                                                                    style:UIBarButtonItemStylePlain target:self                                                                   action:@selector(pullWarn)];     self.navigationItem.leftBarButtonItem = leftButton;          UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];     self.navigationItem.rightBarButtonItem = rightButton; }



源代码:http://download.csdn.net/detail/duxinfeng2010/4576308


     本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1208718,如需转载请自行联系原作者


相关文章
|
SQL 关系型数据库 MySQL
Python系列:教你使用PyMySQL操作MySQL数据库
Python系列:教你使用PyMySQL操作MySQL数据库
661 8
|
C++
有效的字母异位词(C++)
有效的字母异位词(C++)
76 0
|
机器学习/深度学习 数据采集
Azure 机器学习 - 使用 AutoML 预测进行深度学习
Azure 机器学习 - 使用 AutoML 预测进行深度学习
261 0
|
监控 关系型数据库 Go
Sentry SDK 开销测量(Benchmark)
Sentry SDK 开销测量(Benchmark)
277 0
Sentry SDK 开销测量(Benchmark)
|
C++
C++标准转换运算符dynamic_cast
dynamic_cast (expression) dynamic_cast运算符,应该算是四个里面最特殊的一个,因为它涉及到编译器的属性设置,而且牵扯到的面向对象的多态性跟程序运行时的状态也有关系,所以不能完全的使用传统的转换方式来替代。
1112 0
|
存储 Linux 存储虚拟化
|
7天前
|
人工智能 运维 安全
|
5天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
6天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
609 21