本文写的是视图切换,涉及到的内容有
1.实现代码添加Navigation Bar Toolbal;
2.实现在Navigation Bar和Toolbar上用代码添加Bar Button Item;
3.UIView层面的简单动画效果
先把实现结果功能截图贴出来,对应动画效果
开始界面 和第一次向上翻页
向上翻页 和向下翻页
从左向右翻页 和从右向左翻页
开始制作:
1.创建一个新工程叫NVDemo; File->New->Project ->single View Application -> next
2.在新建两个ViewController,分别为FirstViewController和SecondViewController,顺便把XIB一块生成好
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:UIBarButtonSyst