日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS项目之弹出动画二

發(fā)布時間:2024/4/14 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

三、顯示效果

這個還可以進一步優(yōu)化可以加一個標記值可以防止連續(xù)點擊時一直彈出

#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];

回彈效果

有了這個東西,媽媽再也不用擔心我的學習,下面的這幾個都可以做

?

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的IOS项目之弹出动画二的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。