- 浏览: 515499 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
本文写的是视图切换,涉及到的内容有
1.实现代码添加Navigation Bar Toolbal;
2.实现在Navigation Bar和Toolbar上用代码添加Bar Button Item;
3.UIView层面的简单动画效果
[img]
[/img]
[img]
[/img]
[img]
[/img]
[img]
[/img]
开始制作:
1.创建一个新工程叫NVDemo; File->New->Project ->single View Application -> next
[img]
[/img]
2.在新建两个ViewController,分别为FirstViewController和SecondViewController,顺便把XIB一块生成好
[img]
[/img]
3.首先在视图上添加导航栏和导航按钮,经测试导航栏上只能添加两个导航按钮,和设置一个title标题;
我们还需要知道的一个常识是NavigationBar ToolBar Tab Bar 都是44像素,所以在设置他们宽度时候他们的高度设置成44
还有一个通知栏,显示电量信息信号的地方是20像素;
[navigationBar pushNavigationItem:navagationItem animated:YES];涉及到一个压栈的操作,把navigationItem压到navigationBar里,导航栏上只能添加左右两个按钮;所以是setLeftBarButtonItem 和 setRightBarButtonItem,最后再将navigationBar添加到视图之上;
在Toolbar上添加可以添加各种按钮,创建一个可变数组,把添加的按钮全部放到数组上,[toolBar setItems:toolBarArray animated:YES];将数组里按钮集合添加到了toolBar上面,选取图片的时候素材没选好,所以显示出来的图片那个按钮效果不是太好
4.接下来说的是按钮事件,因为需要用到FirstViewController和SecondViewController,在RootViewController.m添加上他们的头文件,为了区别确实是两个视图的切换,在他们的ViewDidLoad函数中初始化视图的背景颜色,
self.view.backgroundColor = [UIColor yellowColor]; 和self.view.backgroundColor = [UIColor redColor];
按钮时间再次也不做过多解释,全部写在注释里了,其他几个都一样,只是修改了动画效果,变化不大,详情可下载源代码研究一下;
咱在这在研究一个问题,在RootAppDelegate.m中我们先看看系统生成的代码
系统直接加载的就是的RootViewController的视图,也就是弹出第一个界面是RootViewController.xib,假如说我想第一个就显示的FirstViewController控制的视图怎么办? 我们就可以在这个函数中进行重写
在delegateApp.h中@class RootViewController后面添加@class FirstViewController;此处声明一个类,在这样当我们添加@property (strong, nonatomic) FirstViewController *fTestViewController;才不会报错;
只需修改两行代码,此处注释原先加载RootViewController视图的代码,可能是我命名的不够合理,RootViewController和rootViewController要区别开,一个工程建立的,一个是系统本身自动生成的
然后再到我们的FirstViewController.m的ViewDidLoad函数先添加几行代码,以示区别
1.实现代码添加Navigation Bar Toolbal;
2.实现在Navigation Bar和Toolbar上用代码添加Bar Button Item;
3.UIView层面的简单动画效果
[img]
[/img]
[img]
[/img]
[img]
[/img]
[img]
[/img]
开始制作:
1.创建一个新工程叫NVDemo; File->New->Project ->single View Application -> next
[img]
[/img]
2.在新建两个ViewController,分别为FirstViewController和SecondViewController,顺便把XIB一块生成好
[img]
[/img]
3.首先在视图上添加导航栏和导航按钮,经测试导航栏上只能添加两个导航按钮,和设置一个title标题;
我们还需要知道的一个常识是NavigationBar ToolBar Tab Bar 都是44像素,所以在设置他们宽度时候他们的高度设置成44
还有一个通知栏,显示电量信息信号的地方是20像素;
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // 创建导航栏,44像素 UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; // 需要在导航栏上创建按钮,所以先创建一个导航栏集合 UINavigationItem *navagationItem = [[UINavigationItem alloc] initWithTitle:@"导航栏"]; UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(pageDown:)]; UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithTitle:@"右测试" style:UIBarButtonItemStyleDone target:self action:@selector(leftpage:)]; [navigationBar pushNavigationItem:navagationItem animated:YES]; [navagationItem setLeftBarButtonItem:leftButton animated:YES]; [navagationItem setRightBarButtonItem:rightButton animated:YES]; [self.view addSubview:navigationBar]; UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 416, 320, 44)]; NSMutableArray *toolBarArray = [NSMutableArray array]; [toolBarArray addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:@selector(switchLoadView:)]]; [toolBarArray addObject:[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(rightpage:)]]; [toolBarArray addObject:[[UIBarButtonItem alloc]initWithTitle:@"MyTitle" style:UIBarButtonItemStylePlain target:self action:nil]]; //UIToolBar上添加图像 [toolBarArray addObject:[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"myImage.png"] style:UIBarButtonItemStylePlain target:self action:nil]]; [toolBar setItems:toolBarArray animated:YES]; [self.view addSubview:toolBar]; }
[navigationBar pushNavigationItem:navagationItem animated:YES];涉及到一个压栈的操作,把navigationItem压到navigationBar里,导航栏上只能添加左右两个按钮;所以是setLeftBarButtonItem 和 setRightBarButtonItem,最后再将navigationBar添加到视图之上;
在Toolbar上添加可以添加各种按钮,创建一个可变数组,把添加的按钮全部放到数组上,[toolBar setItems:toolBarArray animated:YES];将数组里按钮集合添加到了toolBar上面,选取图片的时候素材没选好,所以显示出来的图片那个按钮效果不是太好
4.接下来说的是按钮事件,因为需要用到FirstViewController和SecondViewController,在RootViewController.m添加上他们的头文件,为了区别确实是两个视图的切换,在他们的ViewDidLoad函数中初始化视图的背景颜色,
self.view.backgroundColor = [UIColor yellowColor]; 和self.view.backgroundColor = [UIColor redColor];
按钮时间再次也不做过多解释,全部写在注释里了,其他几个都一样,只是修改了动画效果,变化不大,详情可下载源代码研究一下;
-(void) switchLoadView:(id)sender { //开始一个动画 [UIView beginAnimations:@"Curl" context:nil]; // 设置动画方式,开始和结束时动画效果比较慢 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // 动画持续时间 [UIView setAnimationDuration:1.25]; // 设置动画效果,向上翻页 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; // 首先判断firstView视图父视图是否为空 if (firstView.view.superview == nil) { // 父视图为空,在判断他的子视图是否为空,如果为空在创建一个视图加载上面 if (firstView.view == nil) { FirstViewController *firstViewDemo = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; firstView = firstViewDemo; } // 把seconView视图从父视图中移除 [secondView.view removeFromSuperview]; // 在当前视图插入子视图firstView的视图 [self.view insertSubview:firstView.view atIndex:0]; } else { if (secondView.view == nil) { SecondViewController *secondViewDemo = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; secondView = secondViewDemo; } [firstView.view removeFromSuperview]; [self.view insertSubview:secondView.view atIndex:0]; } // 动画结束 [UIView commitAnimations]; }
咱在这在研究一个问题,在RootAppDelegate.m中我们先看看系统生成的代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; }
系统直接加载的就是的RootViewController的视图,也就是弹出第一个界面是RootViewController.xib,假如说我想第一个就显示的FirstViewController控制的视图怎么办? 我们就可以在这个函数中进行重写
在delegateApp.h中@class RootViewController后面添加@class FirstViewController;此处声明一个类,在这样当我们添加@property (strong, nonatomic) FirstViewController *fTestViewController;才不会报错;
只需修改两行代码,此处注释原先加载RootViewController视图的代码,可能是我命名的不够合理,RootViewController和rootViewController要区别开,一个工程建立的,一个是系统本身自动生成的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. // self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; // self.window.rootViewController = self.viewController; self.fTestViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; // 把根控制视图设置成fTestViewController self.window.rootViewController = self.fTestViewController; [self.window makeKeyAndVisible]; return YES; }
然后再到我们的FirstViewController.m的ViewDidLoad函数先添加几行代码,以示区别
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.view.backgroundColor = [UIColor yellowColor]; UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)]; NSMutableArray *toolBarArray = [NSMutableArray array]; [toolBarArray addObject:[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil]]; UIBarButtonItem *title=[[UIBarButtonItem alloc] initWithTitle:@"My Test" style:UIBarButtonItemStylePlain target:self action:nil]; [toolBar setItems:[NSArray arrayWithObject:title]]; [toolBar setItems:toolBarArray]; [self.view addSubview:toolBar]; }
- NVDemo.zip (91.5 KB)
- 下载次数: 1
发表评论
-
新风作浪博客学习(十九)在iOS虚拟键盘上添加动态隐藏按钮
2013-06-08 09:19 814为了给用户比较良好的交付,想在键盘上添加一个按钮,实时根据键盘 ... -
新风作浪博客学习(十八)openURL的使用(iOS调用系统电话、浏览器、地图、邮件等) .
2013-06-08 09:19 930今天遇见一行代码实现打开一个网页,比起印象里的UIWebVie ... -
新风作浪博客学习(十七)UIImageView响应点击事件 .
2013-06-08 09:19 664有时候会遇到点击一张图片,然后让这张图片触发一个事件,或者是跳 ... -
新风作浪博客学习(十六)Navigation + Tab Bar 常用组合框架 .
2013-06-07 08:50 1191看到很多项目中都采用的是Navigation加Tab Bar组 ... -
新风作浪博客学习(十五)google地图定位小Demo .
2013-06-07 08:50 1057[img][/img]今天写的是一个简单功能的google地图 ... -
新风作浪博客学习(十四)怎样向iPhone模拟器中添加图片 .
2013-06-07 08:50 740在我们做项目中可能需要使用图库,模拟器是有图库的,但是如何像其 ... -
新风作浪博客学习(十三)表视图的分组分区和索引分区 .
2013-06-07 08:50 742本次实现的是表视图的分区和索引,代码和前面都差不多,主要还是代 ... -
新风作浪博客学习(十二)代码实现UITableViewCell表视图单元定制 .
2013-06-07 08:49 928通常情况下我们会希望单元格UITableViewCell显示自 ... -
新风作浪博客学习(十一)UITableViewCell的标记、移动、删除、插入 .
2013-06-06 09:15 1055这篇文章是建立在 代码实现 UITableView与UITa ... -
新风作浪博客学习(十)代码实现 UITableView与UITableViewCell .
2013-06-06 09:14 1108我们常用的表格类视图就是用 UITableView与UITab ... -
新风作浪博客学习(九)两个UIPickerView控件间的数据依赖 .
2013-06-06 09:14 1039本篇实现功能是两个选取器的关联操作,滚动第一个滚轮第二个滚 ... -
新风作浪博客学习(八)代码实现UIPickerView .
2013-06-06 09:14 1236先说一下当个组件选取器,我们创建一个数组NSAray来保存选取 ... -
新风作浪博客学习(七)代码 实现UIDatePicker控件 和 Tab Bar 视图切换 .
2013-06-06 09:15 1068感觉代码写控件都一个理,先在ViewDidLoad中创建控件对 ... -
新风作浪博客学习(五)代码实现UISlider 和 UISwitch .
2013-02-18 09:15 1072本次实现的UISlider和UISwi ... -
新风作浪博客学习(四)把plist里数据显示在textField上 .
2013-02-18 09:15 881在代码实现Lable 、textFie ... -
新风作浪博客学习(三)NSBundle读取图片 plist文件和txt文件
2013-02-18 09:15 1622本文想简单介绍一下NSBundle读取图片到视图上,读取pli ... -
新风作浪博客学习(二)代码实现Lable 、textField创建界面以及键盘的处理
2013-02-18 09:15 1137今天写的是用代码实现一个简单界面,代码重复率比较高,可读性不是 ... -
新风作浪博客学习(一)plist文件读写操作
2013-02-18 09:14 1297文件plist 全名Property List,属性列表文件, ... -
GCDiscreetNotificationView提示视图
2013-06-05 11:17 523先看一下效果图: [img] ... -
iphone开发之适配iphone5
2013-06-05 11:15 1003iphone5出来了,从不用适配的我们也要像android一样 ...
相关推荐
iO2开l中那些高效常用的宏新风作浪的博客T栏新风作浪的博客T栏懂得y|O表现yxP才iy|O锋芒yxO很浅薄O一眼就能被看穿. 沉R来O打根tO让d人S会觉得
新风系统设计PPT学习教案.pptx
新风系统简介PPT学习教案.pptx
专业新风系统资料PPT学习教案.pptx
学习讲正气树新风心得.doc
新风合同.pdf
新风系统设计重点PPT学习教案.pptx
新风系统的设计PPT学习教案.pptx
基于Springboot的新风图书馆管理系统的设计与实现.docx基于Springboot的新风图书馆管理系统的设计与实现.docx基于Springboot的新风图书馆管理系统的设计与实现.docx基于Springboot的新风图书馆管理系统的设计与实现....
2019年新风系统行业概览2020精品报告.rar
电子政务-具有电源自动切换电路的新风控制器.zip
讲正气树新风学习小结.doc
除陋习树新风讲文明主题班会学习教案.pptx
新风系统任务进度表.xlsx新风系统任务进度表.xlsx新风系统任务进度表.xlsx
智能新风系统技术规范书...doc
机房新风系统介绍.pdf
新风系统设计教程.pdf
除陋习树新风讲文明主题班会PPT课件.pptx