ios 视图切换翻页效果

本文介绍了如何在iOS应用中实现视图切换的翻页效果,包括添加NavigationBar和Toolbar,设置Bar Button Item,以及实现UIView的简单动画。通过创建FirstViewController和SecondViewController,设置导航栏和工具栏上的按钮,利用代码触发视图间的切换动画。详细步骤包括在XIB文件中生成视图控制器,设置导航栏和工具栏的高度,以及处理按钮事件来改变视图的背景颜色,提供了一种实现翻页动画的方法。
摘要由CSDN通过智能技术生成

本文写的是视图切换,涉及到的内容有

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
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值