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(0, 0, 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:0.3 delay:0 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(0, frame.size.height-216, 0, 0);[self addSubview:_datePicker];[view addSubview:self];} -(void)dismissView {_selectDate(_datePicker.date);[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{self.frame=CGRectMake(0, 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的FrameCGRect frame1=CGRectMake(0, [UIApplication sharedApplication].keyWindow.bounds.size.height-260, [UIApplication sharedApplication].keyWindow.bounds.size.width, 260);[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(0, 0, 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:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{self.frame=CGRectMake(frame.origin.x, 104, frame.size.width, frame.size.height);;} completion:nil];[UIView animateWithDuration:0.3 delay:0.4 options:UIViewAnimationOptionCurveEaseOut animations:^{self.frame=CGRectMake(frame.origin.x, 0, 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(0, frame.size.height-216, 0, 0);[self addSubview:_datePicker];[view addSubview:self];} -(void)dismissView {_openFlag=false;_selectDate(_datePicker.date);[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{self.frame=CGRectMake(0,- 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.设置在父视图的FrameCGRect frame=CGRectMake(0, 0, self.view.bounds.size.width, 260);[picker showInView:self.view withFrame:frame];
回弹效果
有了这个东西,妈妈再也不用担心我的学习,下面的这几个都可以做
IOS项目之弹出动画二相关推荐
- iOS精品源码,GHConsole图片浏览器圆形进度条音视频传输连击礼物弹出动画
2019独角兽企业重金招聘Python工程师标准>>> 1.可在app中显示的控制台框架GHConsole 2.GKPhotoBrowser--自定义图片浏览器 3.圆形进度条 4. ...
- iOS精品源码,GHConsole图片浏览器圆形进度条音视频传输连击礼物弹出动画 1
1.可在app中显示的控制台框架GHConsole 2.GKPhotoBrowser--自定义图片浏览器 3.圆形进度条 4.音视频实时传输 part2(补充上一贴) 5.RSChat(以前微信写的仿 ...
- Android基础 淡入淡出、上下弹出动画的
今天想到了自己毕业设计时候做的app,里面主页上面的搜索框用到了一个PopupWindow来实现,我就琢磨这在给他加上一个动画,当时真的是什么都不懂,囫囵吞枣的就拿来用了,现在又大概找了两种动画效果来 ...
- iOS-发布按钮动画(类似于闲鱼发布),弹出动画github开源
github开源链接:https://github.com/qxuewei/XWPopMenuVC 项目演示gif动图: 演示效果 弹出动画,发布动画,tabbar弹出,发布按钮弹出选项,类似闲鱼发布 ...
- 【微信小程序封装底部弹出框二】
[微信小程序封装底部弹出框二] <!--index.wxml--> <view><button style="margin-top: 300px;" ...
- jQuery图片翻转弹出动画特效
详细内容请点击 今天我们要来分享一款效果很酷的jQuery图片弹出动画,该动画一共有6组,除了第一组普通弹出外,其他图片弹出的时候均会出现各种不同的翻转动画效果,另外有几组的图片时旋转弹出的,效果也非 ...
- activity从底部弹出动画
要实现activity从底部弹出的动画,一般参考这篇博文就能实现: http://blog.csdn.net/spy19881201/article/details/5861193 但是我的需要还有点 ...
- 微信长按图片无法弹出识别二维码选项解决方案
1.首先页面中有两个二维码的兄弟别忙活了,一个页面中只可以识别其中一个二维码,两个的话需提示用户双击放大二维码进行二维码识别. 2.网页内有一张图片进行二维码识别时长按没有反应(长按图片无法弹出识别二 ...
- 一对一视频聊天软件源码,实现简单侧边栏弹出动画
一对一视频聊天软件源码,实现简单侧边栏弹出动画的相关代码 <!DOCTYPE html> <html lang="en"><head><m ...
最新文章
- 某阿里8年资深程序员求助:连续两次绩效挂掉,被hr辞退不给n+1,怎么办?
- 实践微服务六年,我获得了这些心得体会
- 4.6、Libgdx线程介绍
- taro 重新加载小程序_taro-music一款开源网易云音乐小程序
- 用Transformer完全代替CNN:AN IMAGE IS WORTH 16X16 WORDS: TRANSFORMERS FOR IMAGE RECOGNITION AT SCALE
- 征战蓝桥 —— 2016年第七届 —— C/C++A组第8题——四平方和
- Please copy/symlink the 'missing image' image at xxx
- 提高Java架构师和程序员效率的10个工具
- 二叉树的操作(前,中,后序遍历也叫深度优先遍历,非空结点的个数)递归实现
- 面试微软等公司必备的书
- org.apache.commons.io.IOUtils 的用法(神器,再也不用写冗余代码了)
- IT项目实施管理办法
- 网络工程师(学习课件和视频)
- 401. 二进制手表
- linux环境sphinx搭建,Sphinx安装配置应用
- 游戏自动化协议测试工具的开发个人思路
- CodeForces 964A Splits
- 邮箱每日发送有上限吗?各大邮箱每天限制发信数量多少?
- 洛谷 P1873 [COCI 2011/2012 #5] EKO / 砍树
- IOS证书获取(证书profile文件,p12私钥证书,证书私钥密码,Bundle ID)