IOS项目之弹出动画一

简介:

小区宝首页导航栏左边有一个物业按钮,点击时会出现一个视图动画,之前用的是一个POP第三方,想着几个POP动画就要引用一堆的第三方有点麻烦,就试着自己写了一下,功能实现了,下一步就是优化将其封装一下。下面我用DatePicker做的主要是想着再做出点击弹出按钮在底部出现DatePicker选择器。



#import "ViewController.h"
#import "PageViewController.h"
#import "myView.h"

@interface ViewController ()
@property(nonatomic,strong) myView *myview;
@property(nonatomic,strong) UIDatePicker *dataPicker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"预览" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];
   
    //遮罩层
    _myview=[[myView alloc]initWithFrame:CGRectMake(0,-self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height)];
    _myview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1f];
    //为遮罩层添加手势识别 可以点击遮罩层空白处隐藏视图
    UIGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick)];
    _myview.userInteractionEnabled=YES;
    [_myview addGestureRecognizer:tapgesture];
    
    //设置DatePicker
    _dataPicker=[[UIDatePicker alloc]init];
    _dataPicker.frame=CGRectMake(0, 40, 0, 0);
//    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];
    
    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
    view.backgroundColor=[UIColor blueColor];
    UIButton *btnright=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnright setTitle:@"确定" forState:UIControlStateNormal];
    [btnright addTarget:self action:@selector(btnrightClick:) forControlEvents:UIControlEventTouchUpInside];
    btnright.frame=CGRectMake(self.view.bounds.size.width-40, 0, 40, 40);
    [view addSubview:btnright];
    [_myview addSubview:view];
    [self.view addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
   [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0,40, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
    
    //恢复动画 时间长一些
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.5];
    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
    
}
-(void)tapclick
{
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0, -self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
}
-(void)btnrightClick:(id)sender
{
    NSLog(@"%@",_dataPicker.date);
    [self tapclick];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

我们稍加改动就可以变成从底部弹出视图 这样就完成了闪购模块 宝贝详情中的选择规格的功能


#import "ViewController.h"
#import "PageViewController.h"
#import "myView.h"

@interface ViewController ()
@property(nonatomic,strong) myView *myview;
@property(nonatomic,strong) UIDatePicker *dataPicker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"预览" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];
   
    //遮罩层
    _myview=[[myView alloc]initWithFrame:CGRectMake(0,self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height)];
    _myview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1f];
    //为遮罩层添加手势识别 可以点击遮罩层空白处隐藏视图
    UIGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick)];
    _myview.userInteractionEnabled=YES;
    [_myview addGestureRecognizer:tapgesture];
    
    //设置DatePicker
    _dataPicker=[[UIDatePicker alloc]init];
    _dataPicker.frame=CGRectMake(0, self.view.bounds.size.height-300, 0, 0);
//    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];
    
    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height-340, self.view.bounds.size.width, 40)];
    view.backgroundColor=[UIColor blueColor];
    UIButton *btnright=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnright setTitle:@"确定" forState:UIControlStateNormal];
    [btnright addTarget:self action:@selector(btnrightClick:) forControlEvents:UIControlEventTouchUpInside];
    btnright.frame=CGRectMake(self.view.bounds.size.width-40, 0, 40, 40);
    [view addSubview:btnright];
    [_myview addSubview:view];
    [self.view addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
   [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
    
//    //恢复动画 时间长一些
//    [UIView beginAnimations:@"text" context:nil];
//    [UIView setAnimationDelay:0];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//    [UIView setAnimationDuration:0.5];
//    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height);
//    [UIView commitAnimations];
    
}
-(void)tapclick
{
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
}
-(void)btnrightClick:(id)sender
{
    NSLog(@"%@",_dataPicker.date);
    [self tapclick];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 上面的导航控制器并未被遮罩 ,这样添加时才能使导航控制器遮罩[[UIApplication sharedApplication].keyWindow  addSubview:_myview];


//
//  ViewController.m
//  PhotoBrower
//
//  Created by City--Online on 15/6/16.
//  Copyright (c) 2015年 City--Online. All rights reserved.
//
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
#define SCREENWIDTH  [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height

#import "ViewController.h"
#import "PageViewController.h"
#import "ImageViewController.h"
#import "myView.h"

@interface ViewController ()
@property(nonatomic,strong) myView *myview;
@property(nonatomic,strong) UIDatePicker *dataPicker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"预览" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];
   
    //遮罩层
    _myview=[[myView alloc]initWithFrame:CGRectMake(0,SCREENHEIGHT, WIDTH, SCREENHEIGHT)];
    _myview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1f];
    //为遮罩层添加手势识别 可以点击遮罩层空白处隐藏视图
    UIGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick)];
    _myview.userInteractionEnabled=YES;
    [_myview addGestureRecognizer:tapgesture];
    
    //设置DatePicker
    _dataPicker=[[UIDatePicker alloc]init];
    _dataPicker.frame=CGRectMake(0, SCREENHEIGHT-220, 0, 0);
    //    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];
    
    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT-260, WIDTH, 40)];
    view.backgroundColor=[UIColor blueColor];
    UIButton *btnright=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnright setTitle:@"确定" forState:UIControlStateNormal];
    [btnright addTarget:self action:@selector(btnrightClick:) forControlEvents:UIControlEventTouchUpInside];
    btnright.frame=CGRectMake(self.view.bounds.size.width-40, 0, 40, 40);
    [view addSubview:btnright];
    [_myview addSubview:view];
    [[UIApplication sharedApplication].keyWindow  addSubview:_myview];
//    [self.view addSubview:_myview];
//    [[UIApplication sharedApplication].delegate.window addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, SCREENHEIGHT);
    [UIView commitAnimations];
    
    //恢复动画 时间长一些
//    [UIView beginAnimations:@"text" context:nil];
//    [UIView setAnimationDelay:0];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//    [UIView setAnimationDuration:0.5];
//    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height);
//    [UIView commitAnimations];
    
//    PageViewController *pageVc=[[PageViewController alloc]init];
//    pageVc.hidesBottomBarWhenPushed=YES;
////    [self presentViewController:pageVc animated:YES completion:nil];
//    [self.navigationController pushViewController:pageVc animated:YES];
    
}
-(void)tapclick
{
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0, SCREENHEIGHT, self.view.bounds.size.width, SCREENHEIGHT);
    [UIView commitAnimations];
}
-(void)btnrightClick:(id)sender
{
    NSLog(@"%@",_dataPicker.date);
    [self tapclick];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end



相关文章
|
8月前
|
iOS开发
iOS 动画绘制圆形
iOS 动画绘制圆形
46 1
|
11天前
|
iOS开发
iOS App Store 上传项目报错 缺少隐私政策网址 (URL) 解决方法
iOS App Store 上传项目报错 缺少隐私政策网址 (URL) 解决方法
iOS App Store 上传项目报错 缺少隐私政策网址 (URL) 解决方法
|
10月前
|
缓存 移动开发 前端开发
iOS项目组件化历程
随着业务的发展,App中的页面,网络请求,通用弹层UI,通用TableCell数量就会剧增,需求的开发人员数量也会逐渐增多。 如果所有业务都在同一个App中,并且同时开发人数较少时,抛开代码健壮性不谈,实际的开发体验可能并没有那么糟糕,毕竟作为一个开发,什么地方用什么控件,就跟在HashMap中通过Key获取Value那么简单。 那么当业务成长到需要分化到多个App的时候,组件化的重要性开始体现了。
60 0
|
10月前
|
iOS开发 Perl
将Flutter引入到现有项目中(iOS+Flutter)
将Flutter引入到现有项目中(iOS+Flutter)
|
11月前
|
JavaScript iOS开发
iOS上架之HBuider打包简单项目及注意事项
iOS上架之HBuider打包简单项目及注意事项
|
开发工具 iOS开发
iOS 项目无法在模拟器运行解决办法
iOS 项目无法在模拟器运行解决办法
479 0
|
JavaScript iOS开发
iOS上架之hubuilder打包Vue项目
1.官网下载最新的HBuilderx。 2.准备好一个包含manifest.json的Vue项目,打开进行详细设置,设置完成后,点击保存。 3.首先去App Uploader找到开发证书(开发类型是带development的),点击证书P12下载到桌面。 4.然后根据里面的Bundle ID新建一个描述文件,把描述文件也下载到桌面。 5.菜单项点击‘发行->云打包-打原生安装包’,出现如下图所示弹框,取消广告勾选项,点击打包,把前面下载好的证书,描述文件上传到原生打包列表,提交打包,等待打包完成。(仅以iOS为例) 6.打包完成后,点击“OK”保存安装包到目标文件,发送到手机端安装即可运行。
|
存储 编解码 编译器
iOS项目Project 和 Targets配置详解
最近开始学习完整iOS项目的开发流程和思路,在实际的项目开发过程中,我们通常需要对项目代码和资料进行版本控制和管理,一般比较常用的SVN或者Github进行代码版本控制和项目管理。
707 0
|
JavaScript iOS开发
ios上架之​HBuider打包简单项目及注意事项
ios上架之​HBuider打包简单项目及注意事项
72 0
ios上架之​HBuider打包简单项目及注意事项
|
iOS开发 Perl
iOS开发 -多Target项目如何优雅的使用pods
iOS开发 -多Target项目如何优雅的使用pods
382 0