IOS项目之弹出动画二
在IOS项目之弹出动画一中只是实现也功能,并没有体现面向对象的思想 ,今天就试着把它封装了一下,弹出视图的内容可以根据自定义,此处只是用UIDatePicker来演示
我把它传到了GitHub上 https://github.com/ywcui/YvanDatePicker.git
一、新建一个类YWDatePicker集成UIView
// YvanDatePicker.h #import <UIKit/UIKit.h> typedef void (^selectDate)(NSDate *date); @interface YvanDatePicker : UIView //单利 + (YvanDatePicker *)sharedManager; //block传值获取选择时间 @property(nonatomic,strong) selectDate selectDate; //时间选择控件 可设置属性 @property(nonatomic,strong) UIDatePicker *datePicker; //window全屏显示 -(void)showInWindow; // View中显示 -(void)showInView:(UIView*)view; //在父视图view的相对位置为Frame -(void)showInView:(UIView*)view withFrame:(CGRect)frame; //消失视图 -(void)dismissView; @end
#define MAXHEIGHT [UIScreen mainScreen].bounds.size.height
#import "YvanDatePicker.h"
@interface YvanDatePicker ()
@end
@implementation YvanDatePicker
+ (YvanDatePicker *)sharedManager
{
    static YvanDatePicker *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedAccountManagerInstance = [[self alloc] init];
        sharedAccountManagerInstance.backgroundColor=[UIColor colorWithWhite:0.5 alpha:0.4];
    });
    return sharedAccountManagerInstance;
}
-(void)showInWindow
{
    [self showInView:[UIApplication sharedApplication].keyWindow];
}
-(void)showInView:(UIView*)view
{
    [self showInView:view withFrame:CGRectMake(, , view.frame.size.width, view.frame.size.height)];
}
//frame相对于父视图的位置
-(void)showInView:(UIView*)view withFrame:(CGRect)frame;
{
    //在此可以自定义视图
    self.frame=CGRectMake(frame.origin.x, MAXHEIGHT, frame.size.width, frame.size.height);
    [UIView animateWithDuration: options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.frame=frame;
    } completion:nil];
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissView)];
    [self addGestureRecognizer:tapGesture];
    if (_datePicker==nil) {
        _datePicker=[[UIDatePicker alloc]init];
        _datePicker.locale=[[NSLocale alloc ]initWithLocaleIdentifier:@"zh_Hans_CN"];
        _datePicker.datePickerMode=UIDatePickerModeDate;
        _datePicker.timeZone=[NSTimeZone defaultTimeZone];
    }
    _datePicker.frame=CGRectMake(, frame.size.height-, , );
    [self addSubview:_datePicker];
    [view addSubview:self];
}
-(void)dismissView
{
    _selectDate(_datePicker.date);
    [UIView animateWithDuration: options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.frame=CGRectMake(, MAXHEIGHT, self.frame.size.width , self.frame.size.height);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
二、调用
//
//  ViewController.m
//  YvanDatePicker
//
//  Created by City--Online on 15/6/18.
//  Copyright (c) 2015年 YvanCui. All rights reserved.
//
#import "ViewController.h"
#import "YvanDatePicker.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];
}
-(void)leftClick
{
    YvanDatePicker *picker=[YvanDatePicker sharedManager];
    picker.selectDate=^(NSDate *date)
    {
        NSLog(@"%@",date);
    };
//    //1.设置在父视图的Frame
//    CGRect frame=CGRectMake(10, self.view.bounds.size.height-260, self.view.bounds.size.width-20, 260);
//    [picker showInView:self.view withFrame:frame];
//
//    //2.Window显示
//    [picker showInWindow];
//
//    //3.View全屏显示
//    [picker showInView:self.view];
    //4.相对于Window的Frame
    CGRect frame1=CGRectMake(, [UIApplication sharedApplication].keyWindow.bounds.size.height-, [UIApplication sharedApplication].keyWindow.bounds.size.width, );
    [picker showInView:[UIApplication sharedApplication].keyWindow withFrame:frame1];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
三、显示效果




这个还可以进一步优化可以加一个标记值可以防止连续点击时一直弹出
#define MAXHEIGHT [UIScreen mainScreen].bounds.size.height
#import "YvanDatePicker.h"
@interface YvanDatePicker ()
@property(nonatomic,assign) BOOL openFlag;
@end
@implementation YvanDatePicker
+ (YvanDatePicker *)sharedManager
{
    static YvanDatePicker *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedAccountManagerInstance = [[self alloc] init];
        sharedAccountManagerInstance.backgroundColor=[UIColor colorWithWhite:0.5 alpha:0.4];
    });
    return sharedAccountManagerInstance;
}
-(void)showInWindow
{
    [self showInView:[UIApplication sharedApplication].keyWindow];
}
-(void)showInView:(UIView*)view
{
    [self showInView:view withFrame:CGRectMake(, , view.frame.size.width, view.frame.size.height)];
}
//frame相对于父视图的位置
-(void)showInView:(UIView*)view withFrame:(CGRect)frame;
{
    if (_openFlag) {
        [self dismissView];
        return;
    }
    _openFlag=true;
    self.frame=CGRectMake(frame.origin.x, -frame.size.height, frame.size.width, frame.size.height);
    [UIView animateWithDuration: options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.frame=CGRectMake(frame.origin.x, , frame.size.width, frame.size.height);;
    } completion:nil];
    [UIView animateWithDuration:0.3 delay:0.4 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.frame=CGRectMake(frame.origin.x, , frame.size.width, frame.size.height);;
    } completion:nil];
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissView)];
    [self addGestureRecognizer:tapGesture];
    if (_datePicker==nil) {
        _datePicker=[[UIDatePicker alloc]init];
        _datePicker.locale=[[NSLocale alloc ]initWithLocaleIdentifier:@"zh_Hans_CN"];
        _datePicker.datePickerMode=UIDatePickerModeDate;
        _datePicker.timeZone=[NSTimeZone defaultTimeZone];
    }
    _datePicker.frame=CGRectMake(, frame.size.height-, , );
    [self addSubview:_datePicker];
    [view addSubview:self];
}
-(void)dismissView
{
    _openFlag=false;
    _selectDate(_datePicker.date);
    [UIView animateWithDuration: options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.frame=CGRectMake(,- self.frame.size.height, self.frame.size.width , self.frame.size.height);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
 YvanDatePicker *picker=[YvanDatePicker sharedManager];
    picker.selectDate=^(NSDate *date)
    {
        NSLog(@"%@",date);
    };
//    //1.设置在父视图的Frame
    CGRect frame=CGRectMake(, , self.view.bounds.size.width, );
    [picker showInView:self.view withFrame:frame];
回弹效果

有了这个东西,妈妈再也不用担心我的学习,下面的这几个都可以做



IOS项目之弹出动画二的更多相关文章
- IOS项目之弹出动画终结篇
		
在之前写过IOS项目之弹出动画一.IOS项目之弹出动画二.IOS项目之弹出动画三,今天来一个终极封装已经上传到Github上弹出动画总结篇UIPopoverTableView. UIPopoverTa ...
 - IOS项目之弹出动画三
		
前面写了弹出动画两个,今天做商城时又用到了,看着这个用着蛮普遍的,所以记了下来 // // mallMoreView.h // XQB // // Created by City--Online on ...
 - IOS项目之弹出动画一
		
小区宝首页导航栏左边有一个物业按钮,点击时会出现一个视图动画,之前用的是一个POP第三方,想着几个POP动画就要引用一堆的第三方有点麻烦,就试着自己写了一下,功能实现了,下一步就是优化将其封装一下.下 ...
 - ios等待ualertview弹出动画完成后再跳转至其他页面
		
[self performSelector:@selector(popView:) withObject:nil afterDelay:2.0];
 - 阶段一:为View设置阴影和弹出动画(天气应用)
		
“阶段一”是指我第一次系统地学习Android开发.这主要是对我的学习过程作个记录. 上一篇阶段一:通过网络请求,获得并解析JSON数据(天气应用)完成了应用的核心功能,接下来就要对它进行优化.今天我 ...
 - mac关闭渐隐和弹出动画效果
		
苹果系统应用程序的窗口和对话框每次使用的时候都有华丽的特效,但是如果你感觉这种特效显得有点慢(MacGG闲的蛋疼),那该如何取消掉他呢? 方法很简单,打开"终端"(Finder-& ...
 - 清除ios系统alert弹出框的域名
		
清除ios系统alert弹出框的域名 <script> window.alert = function(name) { var iframe = document.createElemen ...
 - iOS学习——键盘弹出遮挡输入框问题解决方案
		
在iOS或Android等移动端开发过程中,经常遇到很多需要我们输入信息的情况,例如登录时要输入账号密码.查询时要输入查询信息.注册或申请时需要填写一些信息等都是通过我们键盘来进行输入的,在iOS开发 ...
 - 原生Js_实现简单的下拉折叠菜单(添加弹出动画效果)
		
用javascript实现简单的下拉折叠菜单效果 实现步骤 (a)获得各操作的dom对象: (b)在所有菜单按钮对象上添加单击事件: (c)设置所有菜单按钮样式为空,并将当前按钮的样式设置为“acti ...
 
随机推荐
- 自己从0开始学习Unity的笔记 III (C#随机数产生基础练习)
			
自己开始尝试弄一下随机数,照着方法,自己做了个英雄打怪兽的测试 int heroAttack; ; ; Random attack = new Random(); //初始化一个随机数的类 heroA ...
 - NPOI+Json文件解析Excel
			
记点笔记,加深印象!最近有个导入Excel工能需要完成,Excel列名是中文的,导入Excel我用的NPOI插件,如果不对Excel做解析,列名有可能会给我带来一些字符方面的麻烦,于是想到了一个比较l ...
 - 【cocos2d-x 手游研发小技巧(3)Android界面分辨率适配方案】
			
先感叹一下吧~~android的各种分辨率各种适配虐我千百遍,每次新项目我依旧待它如初恋···· 每家公司都有自己项目工程适配的方案,这种东西就是没有最好,只有最适合!!! 这次新项目专项针对andr ...
 - 【文文殿下】 [SDOI2016]生成魔咒
			
字符集大小为1e9.............使用 map 吧 统计本质不同的子串个数是SAM的经典应用之一 本质不同的子串个数其实就是\(\sum max(x)-min(x)+1\) 所以我们新建结点 ...
 - eclipse打包jar文件
			
论文仿真做线性回归分类在人脸识别中应用与研究,在单机下实现LRC算法后,又在Hadoop云平台下实现了该算法.在比较实验结果时候需要放在相同硬件条件下比较.但是LRC单机算法是在windows下的ec ...
 - linux下查找命令总结
			
查找命令总结,which,whereis,find,locate,type http://blog.csdn.net/jessica1201/article/details/8139249 1.f ...
 - linux克隆后修配置
			
第一步:克隆 第二步:vi /etc/sysconfig/network-scripts/ifcfg-eth0 编辑 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM ...
 - 0、weka学习与使用
			
转载自:https://blog.csdn.net/u011067360/article/details/20844443 数据挖掘开源软件:WEKA基础教程 本文档部分来自于网络,随着自己的深入学习 ...
 - 课堂练习:ex  4-20
			
一.习题要求 • 定义一个复数类Complex. • 有相加,输出,模计算函数. • 模计算要求结果保存在第一个复数中. 二.习题内容 //complex.h # ifndef COMPLEX_H # ...
 - Java 子类父类构造方法执行顺序
			
public class Test { class Super { int flag = 1; Super() { test(); } void test() { System.out.println ...