笨鸟学iOS开发(3)view制作及切换
2011-12-07 22:07
176 查看
目的
学习view制作及切换的几种方式
环境
Mac OS X 10.7.2
Xcode4.2
详解
在storyboard中创建另一个ViewController并使用Segue切换
在storyboard中再增加一个ViewController。在两个ViewController中各增加一个按钮。右击按钮,在弹出菜单中拖放“Modal”圈圈到另一个ViewController上放手即可。
在xib文件中创建另一个ViewController并使用代码手动切换
在工程中添加文件,选择创建“UIViewController subclass”,在向导中勾选“With XIB for user interface”,取名为“SecondViewController”,完成后得到3个文件:"SecondViewController.h"、"SecondViewController.m“、"SecondViewController.xib”。
在xib中添加一个按钮,并为其添加事件处理函数,在函数中增加如下代码以用于退出当前的view回到首页:
在首页的ViewController.h中添加此xib对应的变量,如下所示:
背后的切换按钮事件函数代码为:
在代码中手动创建View并使用代码手动切换
预览
在线观看本节开发视频
源代码下载
学习view制作及切换的几种方式
环境
Mac OS X 10.7.2
Xcode4.2
详解
在storyboard中创建另一个ViewController并使用Segue切换
在storyboard中再增加一个ViewController。在两个ViewController中各增加一个按钮。右击按钮,在弹出菜单中拖放“Modal”圈圈到另一个ViewController上放手即可。
在xib文件中创建另一个ViewController并使用代码手动切换
在工程中添加文件,选择创建“UIViewController subclass”,在向导中勾选“With XIB for user interface”,取名为“SecondViewController”,完成后得到3个文件:"SecondViewController.h"、"SecondViewController.m“、"SecondViewController.xib”。
在xib中添加一个按钮,并为其添加事件处理函数,在函数中增加如下代码以用于退出当前的view回到首页:
- (IBAction)exitCurrentView:(id)sender { [self.view removeFromSuperview]; }
在首页的ViewController.h中添加此xib对应的变量,如下所示:
@interface ViewController : UIViewController { SecondViewController* secondViewController; }
背后的切换按钮事件函数代码为:
- (IBAction)switchToSecondView:(id)sender { secondViewController=[[SecondViewController new] initWithNibName:@"SecondViewController" bundle:nil]; [self.view addSubview:secondViewController.view]; }
在代码中手动创建View并使用代码手动切换
- (IBAction)switchToThirdView:(id)sender { //先创建view thirdView=[[UIView alloc] initWithFrame:self.view.bounds]; thirdView.backgroundColor=[UIColor greenColor]; //为view增加控件 UIButton* button=[UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame=CGRectMake(100, 100, 100, 100); [button setTitle:@"回首页" forState:UIControlStateNormal]; [button addTarget:self action:@selector(exitThirdView:) forControlEvents:UIControlEventTouchUpInside]; [thirdView addSubview:button]; //将view显示出来 //加入动画吧 [UIView beginAnimations:@"flipping view" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO]; [self.view addSubview:thirdView]; [UIView commitAnimations]; } - (void)exitThirdView:(id)sender { //也加入动画效果 [UIView beginAnimations:@"flipping view" context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO]; [thirdView removeFromSuperview]; [UIView commitAnimations]; }
预览
在线观看本节开发视频
源代码下载
相关文章推荐
- iOS开发中ViewController切换动画的制作
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- IOS开发—通过ChildViewController实现view的切换
- iOS开发--ChildViewController实现订单页的切换
- ios开发学习--视图切换(View Transition)效果源码分享--系列教程
- iOS开发使用UITableView制作N级下拉菜单的示例
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- iOS开发之pickerView 制作省份选择器
- IOS开发 textView输入文字时键盘切换为中文输入法后,第一个输入的字母变成英文
- Objective-C ,ios,iphone开发基础:多个视图(view)之间的切换2,使用导航栏控制,以及视图之间传值。
- 转载 iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- ios开发(十四)view之间的切换
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- WMPageViewController 更新二级标题,即切换控件的标题--iOS 开发
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
- iOS项目开发实战——Swift实现多个TableView的侧滑与切换
- ios开发 present 出来的viewcontroller 强制横竖屏切换代码分享 (代码不解释)
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)