Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
//
// DrawView.h
// PopView
//
// Created by 123 on 16/5/4.
// Copyright © 2016年 asura. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface DrawView : UIView
/**
* @author asura, 16-05-04 17:05:46
*
* 开始动画
*/
-(void) startAnimating;
/**
* @author asura, 16-05-04 17:05:54
*
* 结束动画
*/
-(void) stopAnimating;
@end
+113
View File
@@ -0,0 +1,113 @@
//
// DrawView.m
// PopView
//
// Created by 123 on 16/5/4.
// Copyright © 2016年 asura. All rights reserved.
//
#import "DrawView.h"
//标示数
static int stage = 0;
@interface DrawView ()
//定时器
@property (nonatomic, strong) NSTimer *timer;
@end
@implementation DrawView
#pragma mark - init
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
}
return self;
}
#pragma mark - animation
-(void) startAnimating
{
if (!self.timer.isValid) {
//时时刷新界面
self.timer =[NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
self.hidden = NO;
stage++;
}
-(void) stopAnimating
{
self.hidden = YES;
[self.timer invalidate];
self.timer = nil;
}
#pragma mark - confgure
//获取颜色
-(UIColor *) getColorForStage:(int) currentStage WithAlpha:(double) alpha
{
int max = 20;
int cycle = currentStage % max;
if (cycle < max/4) {
return [UIColor colorWithRed:232.0/255.0 green:131.0/255.0 blue:37.0/255.0 alpha:alpha];
} else if (cycle < max/4*2) {
return [UIColor colorWithRed:90.0/255.0 green:91.0/255.0 blue:83.0/255.0 alpha:alpha];
} else if (cycle < max/4*3) {
return [UIColor colorWithRed:33.0/255.0 green:31.0/255.0 blue:31.0/255.0 alpha:alpha];
} else {
return [UIColor colorWithRed:19.0/255.0 green:109.0/255.0 blue:198.0/255.0 alpha:alpha];
}
}
//计算线条的终点
-(CGPoint) pointOnInnerCirecleWithAngel:(int) angel
{
double r = self.frame.size.height/2/2;
double cx = self.frame.size.width/2;
double cy = self.frame.size.height/2;
double x = cx + r*cos(M_PI/10*angel);
double y = cy + r*sin(M_PI/10*angel);
return CGPointMake(x, y);
}
//计算线段的起点
-(CGPoint) pointOnOuterCirecleWithAngel:(int) angel
{
double r = self.frame.size.height/2;
double cx = self.frame.size.width/2;
double cy = self.frame.size.height/2;
double x = cx + r*cos(M_PI/10*angel);
double y = cy + r*sin(M_PI/10*angel);
return CGPointMake(x, y);
}
#pragma mark - drawRect
-(void) drawRect:(CGRect)rect
{
CGPoint point;
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 2.0);
for (int i = 1 ; i<=10; ++i) {
CGContextSetStrokeColorWithColor(ctx, [[self getColorForStage:stage+i WithAlpha:0.1 *i] CGColor]);
point = [self pointOnOuterCirecleWithAngel:stage+i];
CGContextMoveToPoint(ctx, point.x, point.y);
point = [self pointOnInnerCirecleWithAngel:stage+i];
CGContextAddLineToPoint( ctx, point.x, point.y);
CGContextStrokePath(ctx);
}
stage++;
}
@end
+95
View File
@@ -0,0 +1,95 @@
//
// PopView.h
// PopView
//
// Created by 123 on 16/4/29.
// Copyright © 2016年 asura. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void(^sureBlock)();
typedef void(^cancleBlock)();
typedef void(^messageBlock)(NSString *message);
@interface PopView : UIButton
#pragma mark - block
//确定按钮 block 回调
@property (nonatomic, copy) sureBlock success;
//取消按钮 block 回调
@property (nonatomic, copy) cancleBlock failure;
//消息 block 回调
@property (nonatomic, copy) messageBlock message;
/** 操作界面 **/
/**
* @author asura, 16-05-04
*
* 普通的弹窗
*
* @param title 提示标题
* @param content 提示的内容
* @param buttonTitle 按钮的标题数组
* @param success 第一个按钮点击回调
* @param failure 第二个按钮点击回调
*/
+ (void)initWithTitle:(NSString *)title content:(NSString *)content buttonTitle:(NSArray *)buttonTitle success:(void (^)())success failure:(void (^)())failure;
/**
* @author asura, 16-05-04
*
* 密文输入弹窗
*
* @param password 提示标题
* @param buttonTitle 按钮的标题数组
* @param message 第一个按钮点击回调
* @param failure 第二个按钮点击回调
*/
+ (void)initWithPassword:(NSString *)password buttonTitle:(NSArray *)buttonTitle message:(void (^)())message failure:(void (^)())failure;
/**
* @author asura, 16-05-04
*
* 评论的弹窗
*
* @param commented 评论标题
* @param buttonTitle 按钮的标题数组
* @param message 第一个按钮点击回调
* @param failure 第二个按钮点击回调
*/
+ (void)initWithCommented:(NSString *)commented buttonTitle:(NSArray *)buttonTitle message:(void (^)(NSString *message))message failure:(void (^)())failure;
/** 状态提示界面 **/
/**
* @author asura, 16-05-04
*
* 成功状态提示
*
* @param successString 提示的字符
*/
+ (void)initWithSuccessString:(NSString *)successString;
/**
* @author asura, 16-05-04
*
* 失败状态提示
*
* @param failureString 提示的字符
*/
+ (void)initWithFailureString:(NSString *)failureString;
/**
* @author asura, 16-05-04
*
* 等待状态的show
*
* @param waitingString 提示的字符
*/
+ (void)initWithWaitingString:(NSString *)waitingString;
+ (void)initWithWaiting;
/**
* @author asura, 16-05-04
*
* 等待状态的dismiss
*/
+ (void)dissmissPopview;
@end
+541
View File
@@ -0,0 +1,541 @@
//
// PopView.m
// PopView
//
// Created by 123 on 16/4/29.
// Copyright © 2016年 asura. All rights reserved.
//
#import "PopView.h"
#import "DrawView.h"
//屏幕宽和高
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
typedef NS_ENUM(NSInteger, PopViewType){
PopViewNormalType = 0,
PopViewPasswordType = 1 << 1,
PopViewCommentedType = 1 << 2,
PopViewSuccessType = 1 << 3,
PopViewFailureType = 1 << 4,
PopViewWaitingType = 1 << 5
};
#define kScreenFrame [UIScreen mainScreen].bounds
#define kScreenSpacing 10
@interface PopView () <UITextViewDelegate>
/** 操作界面 **/
@property (nonatomic, strong) UIWindow *window;
//底层背景视图
@property (nonatomic, strong) UIButton *bottomButton;
//记录创建该视图时当前 window 的等级
@property (nonatomic, assign) NSInteger windowLevel;
//提示标题
@property (nonatomic, copy) NSString *title;
//提示内容
@property (nonatomic, copy) NSString *content;
//按钮标题
@property (nonatomic, strong) NSArray *buttonTitle;
//存放 textField的数组
@property (nonatomic, strong) NSMutableArray *textFields;
//回调信息
@property (nonatomic, copy) NSString *messagString;
//弹出视图的样式
@property (nonatomic, assign) PopViewType popViewType;
//记录点击的标示
@property (nonatomic, assign) BOOL isHandle;
/** 状态提示界面 **/
//状态消息
@property (nonatomic, copy) NSString *showMessage;
//画图板
@property (nonatomic, strong) CAShapeLayer *shaperLayer;
//加载控件
@property (nonatomic, strong) DrawView *drawView;
@end
@implementation PopView
// Only override drawRect: if you perform custom drawing.
// An emprty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
#pragma mark - lazyloaded
- (NSMutableArray *)textFields{
if (!_textFields) {
self.textFields = [NSMutableArray array];
}
return _textFields;
}
#pragma mark - init
//普通视图
+ (void)initWithTitle:(NSString *)title content:(NSString *)content buttonTitle:(NSArray *)buttonTitle success:(void (^)())success failure:(void (^)())failure{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth * 2 / 3, kScreenHeight / 6)];
popView.title = title;
popView.content = content;
popView.buttonTitle = buttonTitle;
popView.popViewType = PopViewNormalType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureCenterView];
popView.success = success;
popView.failure = failure;
}
//密文视图
+ (void)initWithPassword:(NSString *)password buttonTitle:(NSArray *)buttonTitle message:(void (^)())message failure:(void (^)())failure{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth * 2 / 3, kScreenHeight / 6)];
popView.title = password;
popView.buttonTitle = buttonTitle;
popView.popViewType = PopViewPasswordType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureCenterView];
popView.message = message;
popView.failure = failure;
}
//评论视图
+ (void)initWithCommented:(NSString *)commented buttonTitle:(NSArray *)buttonTitle message:(void (^)(NSString *))message failure:(void (^)())failure{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth * 2 / 3, kScreenHeight / 6)];
popView.title = commented;
popView.buttonTitle = buttonTitle;
popView.popViewType = PopViewCommentedType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureCenterView];
popView.message = message;
popView.failure = failure;
}
//成功提示
+ (void)initWithSuccessString:(NSString *)successString{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenHeight / 8, kScreenHeight / 8)];
popView.showMessage = successString;
popView.popViewType = PopViewSuccessType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureStatedCenterView];
}
//失败提示
+ (void)initWithFailureString:(NSString *)failureString{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenHeight / 8, kScreenHeight / 8)];
popView.showMessage = failureString;
popView.popViewType = PopViewFailureType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureStatedCenterView];
}
//状态等待
+ (void)initWithWaitingString:(NSString *)waitingString{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenHeight / 8, kScreenHeight / 8)];
popView.showMessage = waitingString;
popView.popViewType = PopViewWaitingType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureStatedCenterView];
}
//记载等待
+ (void)initWithWaiting{
PopView *popView = [[PopView alloc]initWithFrame:CGRectMake(0, 0, kScreenHeight / 8 - 10, kScreenHeight / 8 - 10)];
popView.popViewType = PopViewWaitingType;
[popView initConfgureBottomButtonAndWindow];
[popView initConfgureStatedCenterView];
}
//配置底层视图
- (void)initConfgureBottomButtonAndWindow{
self.window = [[[UIApplication sharedApplication]delegate]window];
self.windowLevel = self.window.windowLevel;
self.window.windowLevel = UIWindowLevelAlert + 1;
self.bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.bottomButton.frame = kScreenFrame;
self.bottomButton.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.2];
self.window.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.4];
self.backgroundColor = [UIColor whiteColor];
[self.window addSubview:self.bottomButton];
[self.bottomButton addSubview:self];
}
//配置弹出视图及其子视图
- (void)initConfgureCenterView{
//self
self.center = self.bottomButton.center;
self.layer.cornerRadius = kScreenSpacing;
self.layer.masksToBounds = YES;
CGFloat selfWidth = CGRectGetWidth(self.frame);
CGFloat selfHeight = CGRectGetHeight(self.frame);
//title
UILabel *titleLabel = [self addSubViwLableWithFrame:CGRectMake(kScreenSpacing, 0, selfWidth - kScreenSpacing * 2, selfHeight / 3) title:self.title sizeFont:17 isTitle:YES];
if (self.popViewType == PopViewPasswordType) {
//密文
[self addTextFieldWithSelfWidth:selfWidth titleLabel:titleLabel];
}else if (self.popViewType == PopViewNormalType){
//普通
[self addSubViwLableWithFrame:CGRectMake(kScreenSpacing, CGRectGetMaxY(titleLabel.frame), selfWidth - kScreenSpacing * 2, selfHeight / 3) title:self.content sizeFont:14 isTitle:NO];
}else if (self.popViewType == PopViewCommentedType){
//评论
[self addTextViewWithSelfWidth:selfWidth selfHeight:selfHeight titleLabel:titleLabel];
}
//button
[self addButtonWithSelfWidth:selfWidth selfHeight:selfHeight];
//分割线
[self addLineWithSelfWidth:selfWidth selfHeight:selfHeight];
//显示动画
[self showAnimationPopView];
}
- (id)addSubViwLableWithFrame:(CGRect)frame title:(NSString *)title sizeFont:(int)sizeFont isTitle:(BOOL)isTitle{
UILabel *titleLabel = [[UILabel alloc]initWithFrame:frame];
[self addSubview:titleLabel];
titleLabel.text = title;
titleLabel.textAlignment = NSTextAlignmentCenter;
if (isTitle) {
titleLabel.font = [UIFont boldSystemFontOfSize:sizeFont];
}else{
titleLabel.font = [UIFont systemFontOfSize:sizeFont];
}
return titleLabel;
}
//textField
- (void)addTextFieldWithSelfWidth:(CGFloat)selfWidth titleLabel:(UILabel *)titleLabel{
CGFloat textFieldWidth = (selfWidth - kScreenSpacing * 7) / 6;
for (int i = 0; i < 6; i ++) {
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake((textFieldWidth + kScreenSpacing) * i + kScreenSpacing, CGRectGetMaxY(titleLabel.frame), textFieldWidth, textFieldWidth)];
[self addSubview:textField];
textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
textField.layer.borderWidth = 1;
[textField addTarget:self action:@selector(editigChanged:) forControlEvents:UIControlEventEditingChanged];
textField.tag = 200 + i;
textField.keyboardType = UIKeyboardTypeNumberPad;
[self.textFields addObject:textField];
textField.secureTextEntry = YES;
textField.textAlignment = NSTextAlignmentCenter;
if (i != 0) {
textField.enabled = NO;
}
if (i == 0) {
[textField becomeFirstResponder];
}
}
}
//button
- (void)addButtonWithSelfWidth:(CGFloat)selfWidth selfHeight:(CGFloat)selfHeight{
CGFloat buttonWidth = (selfWidth - kScreenSpacing * (self.buttonTitle.count + 1)) / self.buttonTitle.count;
for (int i = 0; i < self.buttonTitle.count; i ++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake((buttonWidth + kScreenSpacing ) * i + kScreenSpacing,selfHeight * 2 / 3, buttonWidth, selfHeight / 3);
[button setTitle:self.buttonTitle[i] forState:UIControlStateNormal];
[self addSubview:button];
button.tag = 100 + i;
[button addTarget:self action:@selector(handleAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:15];
}
}
//分割线
- (void)addLineWithSelfWidth:(CGFloat)selfWidth selfHeight:(CGFloat)selfHeight{
UIView *hView = [[UIView alloc]initWithFrame:CGRectMake(0, selfHeight * 2 / 3 - 1, selfWidth, 1)];
hView.backgroundColor = [UIColor lightGrayColor];
[self addSubview:hView];
if (self.buttonTitle.count == 2) {
UIView *Vview = [[UIView alloc]initWithFrame:CGRectMake(selfWidth / 2 - 0.5, selfHeight * 2 / 3, 1, selfHeight / 3)];
Vview.backgroundColor = [UIColor lightGrayColor];
[self addSubview:Vview];
}
}
- (void)addTextViewWithSelfWidth:(CGFloat)selfWidth selfHeight:(CGFloat)selfHeight titleLabel:(UILabel *)titleLabel{
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(kScreenSpacing, CGRectGetMaxY(titleLabel.frame), selfWidth - kScreenSpacing * 2, selfHeight / 3 - 2)];
textView.layer.cornerRadius = kScreenSpacing / 2;
textView.layer.masksToBounds = YES;
textView.layer.borderColor = [UIColor lightGrayColor].CGColor;
textView.layer.borderWidth = 1;
[self addSubview:textView];
textView.delegate = self;
}
//状态模式的配置子视图
- (void)initConfgureStatedCenterView{
//self
self.center = self.bottomButton.center;
self.layer.cornerRadius = kScreenSpacing;
self.layer.masksToBounds = YES;
CGFloat selfWidth = CGRectGetWidth(self.frame);
CGFloat selfHeight = CGRectGetHeight(self.frame);
if (self.popViewType == PopViewWaitingType) {
//laoding
[self loadingWithSelfWidth:selfWidth selfHeight:selfHeight];
}else{
//画图
[self drawRectWithSelfWidth:selfWidth selfHeight:selfHeight];
}
// label
[self addSubViwLableWithFrame:CGRectMake(kScreenSpacing, selfHeight * 2 / 3 - 5, selfWidth - kScreenSpacing * 2, selfHeight / 3) title:self.showMessage sizeFont:14 isTitle:NO];
[self showAnimationPopView];
[self drawRectAnimation];
//存在,则直接返回
if (self.drawView) return;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.9 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self disssmissAnimationPopView];
});
}
//移除
+ (void)dissmissPopview{
NSArray *windows = [UIApplication sharedApplication].windows;
for (UIView *window in windows) {
if ([window isKindOfClass:[UIWindow class]]) {
for (UIView *view in window.subviews) {
if ([view isKindOfClass:[UIButton class]]) {
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[PopView class]]) {
[((PopView *)subView) disssmissAnimationPopView];
[((PopView *)subView).drawView stopAnimating];
}
}
}
}
}
}
}
- (void)drawRectWithSelfWidth:(CGFloat)selfWidth selfHeight:(CGFloat)selfHeight{
//画图
CGPoint centerPoint = CGPointMake(selfWidth / 2, selfHeight / 3);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:centerPoint radius:selfHeight / 4 startAngle:0 endAngle:2 * M_PI clockwise:YES];
bezierPath.lineCapStyle = kCGLineCapRound;
bezierPath.lineJoinStyle = kCGLineJoinRound;
if (self.popViewType == PopViewSuccessType) {
//成功状态
[bezierPath moveToPoint: CGPointMake(selfWidth / 2 - selfHeight / 4 + 5, selfHeight / 3 + 5)];
[bezierPath addLineToPoint: CGPointMake(selfWidth / 2 - 5, selfHeight / 3 + selfHeight / 4 - 5)];
[bezierPath addLineToPoint: CGPointMake(selfWidth / 2 + selfHeight / 8, selfHeight / 4)];
[bezierPath addLineToPoint:CGPointMake(selfWidth / 2 + selfHeight / 6, selfHeight / 4)];
}else if (self.popViewType == PopViewFailureType){
//失败状态
[bezierPath moveToPoint:CGPointMake(selfWidth / 2 - selfHeight / 4 + kScreenSpacing, selfHeight / 5)];
[bezierPath addLineToPoint:CGPointMake(selfWidth / 2 + selfHeight / 8, selfHeight / 2)];
[bezierPath moveToPoint:CGPointMake(selfWidth / 2 + selfHeight / 4 - kScreenSpacing, selfHeight / 5)];
[bezierPath addLineToPoint:CGPointMake(selfWidth / 2 - selfHeight / 4 + kScreenSpacing, selfHeight / 2)];
}
self.shaperLayer = [CAShapeLayer layer];
self.shaperLayer.frame = self.bounds;
self.shaperLayer.lineWidth = 2;
self.shaperLayer.strokeColor = [UIColor blueColor].CGColor;
self.shaperLayer.fillColor = [UIColor clearColor].CGColor;
self.shaperLayer.path = bezierPath.CGPath;
[self.layer addSublayer:self.shaperLayer];
}
- (void)loadingWithSelfWidth:(CGFloat)selfWidth selfHeight:(CGFloat)selfHeight{
//加载控件
self.drawView = [[DrawView alloc]initWithFrame:CGRectMake(kScreenSpacing, kScreenSpacing, selfWidth - kScreenSpacing * 2, selfHeight * 2 / 3 - kScreenSpacing * 2)];
[self addSubview:self.drawView];
[self.drawView startAnimating];
}
#pragma mark - animation
//show动画
- (void)showAnimationPopView{
self.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:0.6 delay:0 usingSpringWithDamping:0.55 initialSpringVelocity:0 options:UIViewAnimationOptionTransitionNone animations:^{
self.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
}];
}
// dissmiss 动画
- (void)disssmissAnimationPopView{
//设置还原 window 的 leavel
self.window.windowLevel = self.windowLevel;
[UIView animateKeyframesWithDuration:0.4 delay:0 options:UIViewKeyframeAnimationOptionRepeat animations:^{
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
basicAnimation.fromValue = @1.0f;
basicAnimation.toValue = @0.f;
basicAnimation.duration = 0.4;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[self.layer addAnimation:basicAnimation forKey:@"scale"];
} completion:^(BOOL finished) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.bottomButton removeFromSuperview];
});
}];
}
//画图动画
- (void)drawRectAnimation{
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
basicAnimation.fromValue = @0;
basicAnimation.toValue = @1;
basicAnimation.duration = 0.6;
[self.shaperLayer addAnimation:basicAnimation forKey:@"strokeEnd"];
}
#pragma mark - action
//点击事件
- (void)handleAction:(UIButton *)sender{
//先取消输入框的第一响应者
if (self.popViewType == PopViewCommentedType) {
for (UIView *view in self.subviews) {
if ([view isKindOfClass:[UITextView class]]) {
[((UITextView *)view) resignFirstResponder];
}
}
}
if (sender.tag == 100) {
self.success ? self.success() : nil;
self.message ? self.message(self.messagString) : nil;
}else{
self.failure ? self.failure() : nil;
}
if (!self.isHandle) {
[self disssmissAnimationPopView];
self.isHandle = YES;
}
}
//textFiled 的事件
- (void)editigChanged:(UITextField *)textField{
switch (textField.tag) {
case 200:
{
[self confgureTextFieldWithChangedTextFiled:textField indexTage:0];
self.messagString = textField.text;
}
break;
case 201:
{
[self confgureTextFieldWithChangedTextFiled:textField indexTage:1];
self.messagString = [NSString stringWithFormat:@"%@%@",self.messagString,textField.text];
}
break;
case 202:
{
[self confgureTextFieldWithChangedTextFiled:textField indexTage:2];
self.messagString = [NSString stringWithFormat:@"%@%@",self.messagString,textField.text];
}
break;
case 203:
{
[self confgureTextFieldWithChangedTextFiled:textField indexTage:3];
self.messagString = [NSString stringWithFormat:@"%@%@",self.messagString,textField.text];
}
break;
case 204:
{
[self confgureTextFieldWithChangedTextFiled:textField indexTage:4];
self.messagString = [NSString stringWithFormat:@"%@%@",self.messagString,textField.text];
}
break;
case 205:
{
[self confgureTextFieldWithChangedTextFiled:textField indexTage:5];
self.messagString = [NSString stringWithFormat:@"%@%@",self.messagString,textField.text];
}
break;
default:
break;
}
}
- (void)confgureTextFieldWithChangedTextFiled:(UITextField *)changedTextFiled indexTage:(int)indexTage{
if (changedTextFiled == self.textFields[indexTage]) {
//限制输入的字符长度
if (changedTextFiled.text.length == 1) {
//输入完之后关闭交互
changedTextFiled.enabled = NO;
//选择交互和直接返回的判断
if (indexTage + 1 == self.textFields.count){
UIButton *sureButton = [self viewWithTag:100];
sureButton.enabled = YES;
}else{
((UITextField *)self.textFields[indexTage + 1]).enabled = YES;
[((UITextField *)self.textFields[indexTage + 1]) becomeFirstResponder];
}
}
}
}
#pragma mark - layoutSubviews
- (void)layoutSubviews{
[super layoutSubviews];
self.alpha = 0.7;
[self.window insertSubview:self.bottomButton atIndex:INT32_MAX];
//如果是密码输入.则关掉确定按钮的交互
if (self.textFields.count != 0) {
UIButton *sureButton = [self viewWithTag:100];
sureButton.enabled = NO;
}
}
#pragma mark - UITextView delegate
- (void)textViewDidEndEditing:(UITextView *)textView{
self.messagString = textView.text;
}
@end
+30
View File
@@ -0,0 +1,30 @@
//
// WBSPopShareView.h
// WEIBOShareDemo
//
// Created by 赚发2 on 16/7/5.
// Copyright © 2016年 fengwang. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void(^handleShare)(UIButton *sender);
@interface WBSPopShareView : UIView
/**
* 初始化方法
*
* @param frame frame
* @param images 图标数组
* @param titles 标题数组(可以为空)
*
* @return WBSPopShareView
*/
- (instancetype)initWithFrameWithFrame:(CGRect)frame images:(NSArray <NSString *> *)images titles:(NSArray <NSString *> *)titles;
/** 回调 block */
@property (nonatomic, copy) handleShare handleShareBlock;
@end
+269
View File
@@ -0,0 +1,269 @@
//
// WBSPopShareView.m
// WEIBOShareDemo
//
// Created by 赚发2 on 16/7/5.
// Copyright © 2016年 fengwang. All rights reserved.
//
#import "WBSPopShareView.h"
#import "UIButton+BBTButton.h"
#import "UIView+EXTENSION.h"
static NSUInteger const linesSpacing = 10;
static NSUInteger const columnSpacing = 20;
@interface WBSPopShareView ()
{
/** 上部预留 view */
UIView *_topView;
/** 容器 view */
UIView *_contentView;
/** 操作 view */
UIView *_operationView;
/** 图片数组 */
NSArray *_images;
/** 标题数组 */
NSArray *_titles;
/** 分享 button 宽 */
CGFloat _buttonWidth;
/** 分享 button 高 */
CGFloat _buttonHeight;
/** 取消按钮 */
UIButton *_cancleButton;
}
/** 存放 button 的数组 */
@property (nonatomic, strong) NSMutableArray *buttons;
@end
@implementation WBSPopShareView
- (NSMutableArray *)buttons{
if (!_buttons) {
self.buttons = [NSMutableArray array];
}
return _buttons;
}
- (instancetype)initWithFrameWithFrame:(CGRect)frame images:(NSArray<NSString *> *)images titles:(NSArray<NSString *> *)titles{
self = [super initWithFrame:frame];
if (self) {
_images = images;
_titles = titles;
[self confguireSubViews];
[self showWBSPopShareView];
}
return self;
}
#pragma mark - 配置子视图 -
- (void)confguireSubViews{
//self
self.alpha = 0;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dissmissTapGesture)];
[self addGestureRecognizer:tapGesture];
//毛玻璃
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
visualEffectView.frame = self.bounds;
[self addSubview:visualEffectView];
UIView *backgroundView = [[UIView alloc] initWithFrame:visualEffectView.frame];
[visualEffectView addSubview:backgroundView];
backgroundView.alpha = 0.95f;
//_contentView
_contentView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height / 2 - 30, self.width, self.height / 2)];
_contentView.backgroundColor = [UIColor clearColor];
[self addSubview:_contentView];
//_operationView
_operationView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height - 30, self.width, 30)];
_operationView.backgroundColor = [UIColor whiteColor];
[self addSubview:_operationView];
//_topView
_topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height / 2 - 30)];
_topView.backgroundColor = [UIColor clearColor];
[self addSubview:_topView];
//底部关闭的 button
UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
_cancleButton = cancleButton;
cancleButton.frame = CGRectMake(_operationView.width / 2 - _operationView.height / 2, 0, _operationView.height, _operationView.height);
[cancleButton setImage:[UIImage imageNamed:@"tabbar_compose_background_icon_close"] forState:UIControlStateNormal];
[_operationView addSubview:cancleButton];
[cancleButton addTarget:self action:@selector(dissmissSelf:) forControlEvents:UIControlEventTouchUpInside];
//添加分享按钮
[self addShareButtons];
}
- (void)addShareButtons{
CGFloat buttonWidth = (self.width - 4 * linesSpacing) / 3;
CGFloat buttonHeight = buttonWidth;
_buttonWidth = buttonWidth;
_buttonHeight = buttonHeight;
int index = 0;
for (int i = 0; i < _images.count; i ++) {
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
index = i;
if (i >= 3) {
index -= 3;
}
shareButton.frame = CGRectMake(linesSpacing + (linesSpacing + buttonWidth) * index, _contentView.height, buttonWidth, buttonHeight);
[_contentView addSubview:shareButton];
shareButton.titleLabel.font = [UIFont systemFontOfSize:14];
shareButton.adjustsImageWhenHighlighted = NO;
[shareButton addTarget:self action:@selector(handleDownAction:) forControlEvents:UIControlEventTouchDown];
[shareButton addTarget:self action:@selector(handleUpInsidAction:) forControlEvents:UIControlEventTouchUpInside];
[shareButton addTarget:self action:@selector(handleDragAction:) forControlEvents:UIControlEventTouchDragOutside];
[shareButton setImage:[UIImage imageNamed:_images[i]] forState:UIControlStateNormal];
[self.buttons addObject:shareButton];
shareButton.tag = i + 100;
if (_titles.count != 0 || _titles != nil) {
//如果是图文,重新布局
[shareButton setTitle:_titles[i] forState:UIControlStateNormal];
[shareButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[shareButton layoutButtonWithEdgeInsetsStyle:UKButtonEdgeInsetsStyleTop imageTitleSpace:3];
}
}
}
#pragma mark - show and dissmiss -
- (void)showWBSPopShareView{
int index = 0;
for (int i = 0; i < _buttons.count; i ++) {
UIButton *shareButton = _buttons[i];
NSInteger count = i / 3;
index = i;
if (i >= 3) {
index -= 3;
}
//shareButton 动画
[UIView animateWithDuration:0.6 delay:i * 0.1 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
shareButton.originY = columnSpacing + (columnSpacing + _buttonHeight) * count;
} completion:^(BOOL finished) {
}];
//背景动画
[UIView animateWithDuration:0.4 animations:^{
self.alpha = 1;
}];
}
}
- (void)dissmissSelf:(UIButton *)sender{
for (int i = 0; i < _buttons.count; i ++) {
UIButton *shareButton = _buttons[i];
[UIView animateWithDuration:0.6 delay:i * 0.1 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
shareButton.originY = _contentView.height;
} completion:^(BOOL finished) {
}];
}
//消失按钮动画
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
basicAnimation.fromValue = @0;
basicAnimation.toValue = @(M_PI_4);
basicAnimation.duration = 0.3;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[sender.layer addAnimation:basicAnimation forKey:@"rotation"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//背景动画
[UIView animateWithDuration:0.2 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
if (finished) {
[self removeFromSuperview];
}
}];
});
}
#pragma mark - handle action -
- (void)handleDownAction:(UIButton *)sender{
[UIView animateWithDuration:0.2 animations:^{
CGAffineTransform tranform = CGAffineTransformMakeScale(1.3, 1.3);
sender.transform = tranform;
} completion:^(BOOL finished) {
}];
}
- (void)handleUpInsidAction:(UIButton *)sender{
[UIView animateWithDuration:0.4 animations:^{
CGAffineTransform tranform = CGAffineTransformMakeScale(1.8, 1.8);
sender.transform = tranform;
sender.alpha = 0;
for (UIButton *shareButton in _buttons) {
if (shareButton != sender) {
CGAffineTransform tranform = CGAffineTransformMakeScale(0.3, 0.3);
shareButton.transform = tranform;
}
}
} completion:^(BOOL finished) {
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.2 animations:^{
self.alpha = 0;
//消失按钮动画
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
basicAnimation.fromValue = @0;
basicAnimation.toValue = @(M_PI_4);
basicAnimation.duration = 0.2;
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
[_cancleButton.layer addAnimation:basicAnimation forKey:@"rotation"];
} completion:^(BOOL finished) {
//回调
_handleShareBlock ? _handleShareBlock(sender) : nil;
[self removeFromSuperview];
}];
});
}
- (void)handleDragAction:(UIButton *)sender{
[UIView animateWithDuration:0.2 animations:^{
CGAffineTransform tranform = CGAffineTransformMakeScale(1, 1);
sender.transform = tranform;
} completion:^(BOOL finished) {
}];
}
- (void)dissmissTapGesture{
[self dissmissSelf:_cancleButton];
}
@end