login 适配 se 5s 新增icon 主页修改

This commit is contained in:
lianxiang
2018-09-04 21:54:04 +08:00
parent 3a3e6eeee9
commit 17d4481f2c
66 changed files with 1136 additions and 306 deletions
@@ -7,7 +7,7 @@
//
#import <UIKit/UIKit.h>
@interface GiGaMaskTaskViewController : UIViewController
#import "GiGaBaseViewController.h"
@interface GiGaMaskTaskViewController : GiGaBaseViewController
@end
@@ -25,42 +25,61 @@
#import "GiGaMeViewController.h"
#import "GiGaFlyingCommitInputView.h"
#import "GiGaFlingCommitVC.h"
@interface GiGaMaskTaskViewController ()<UITextFieldDelegate>
#import "MaskTimeCircularProgressView.h"
#import "UINavigationBar+Custom.h"
@interface GiGaMaskTaskViewController ()<MaskCirCularProGressViewDelegate>
{
AVAudioPlayer *_musicPalyer;
}
@property(nonatomic,strong)MaskViewBootomWaringView *waringView;
@property(nonatomic,strong)UILabel *countLabel;
@property (strong ,nonatomic) LXCountTimer *timer;
@property(nonatomic,strong)UILabel *descLabl;
@property(nonatomic,strong)UIView *descBackView;
//@property (nonatomic,strong) GiGaFlyingCommitInputView *commitInputView;
@property(nonatomic,strong) UIImageView *maskImageView;
@property(nonatomic,strong) UIImageView *faceView;
//@property(nonatomic,strong) UIDynamicAnimator *animator;
//@property(nonatomic,strong) UIAttachmentBehavior *attachmentBehavior;
@property(nonatomic) CGPoint attachPoint;
//@property(nonatomic) UISnapBehavior *snapBehavior;
@property(nonatomic,strong) MaskTimeCircularProgressView *cicleProgressView;
@end
@implementation GiGaMaskTaskViewController
//倒计时label
-(UILabel *)countLabel{
if (!_countLabel) {
_countLabel = [[UILabel alloc] init];
_countLabel.textColor = [UIColor redColor];
_countLabel.text = @"00:00";
_countLabel.textAlignment = NSTextAlignmentCenter;
//提示label
- (UILabel *)descLabl{
if(!_descLabl){
_descLabl = [[UILabel alloc] init];
_descLabl.text = @"请点击或按住面膜上滑敷到脸部开始倒计时";
_descLabl.textAlignment = NSTextAlignmentCenter;
_descLabl.numberOfLines = 2;
_descLabl.textColor = GIGARGB(89, 216, 197, 1);
_descLabl.font = [UIFont fontWithName:GIGA_FONTNAME size:11];
}
return _countLabel;
return _descLabl;
}
- (UIView *)descBackView{
if(!_descBackView){
_descBackView = [[UIView alloc] init];
_descBackView.layer.borderWidth = 1;
_descBackView.layer.borderColor = GIGARGB(120, 217, 202, 1).CGColor;
_descBackView.layer.masksToBounds = YES;
_descBackView.layer.cornerRadius = 1;
}
return _descBackView;
}
//面膜
- (UIImageView *)maskImageView{
if (!_maskImageView) {
_maskImageView = [[UIImageView alloc] init];
_maskImageView.userInteractionEnabled = YES;
_maskImageView.backgroundColor = [UIColor purpleColor];
//_maskImageView.backgroundColor = [UIColor purpleColor];
_maskImageView.image = [UIImage imageNamed:@"img_bg"];
UIPanGestureRecognizer *pangesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureAction:)];
[_maskImageView addGestureRecognizer:pangesture];
}
@@ -70,12 +89,36 @@
- (UIImageView *)faceView{
if (!_faceView) {
_faceView = [[UIImageView alloc] init];
_faceView.backgroundColor = [UIColor lightGrayColor];
//_faceView.backgroundColor = [UIColor lightGrayColor];
_faceView.userInteractionEnabled = YES;
_faceView.image = [UIImage imageNamed:@"img_bg_head"];
}
return _faceView;
}
//倒计时圆环
- (MaskTimeCircularProgressView *)cicleProgressView{
if (!_cicleProgressView) {
_cicleProgressView = [[MaskTimeCircularProgressView alloc] initWithFrame:CGRectMake(100, 500, 136, 136) backColor:GIGARGB(22, 22, 22, 1) progressColor:[UIColor blueColor] lineWidth:10 timeinterval:10];
_cicleProgressView.delegate = self;
_cicleProgressView.hidden = YES;
}
return _cicleProgressView;
}
//底部提示栏
- (MaskViewBootomWaringView *)waringView{
if (!_waringView) {
self.waringView = [[MaskViewBootomWaringView alloc] init];
self.waringView.frame = CGRectMake(0,CGRectGetMaxY(self.view.frame), self.view.frame.size.width, 60);
}
return _waringView;
}
//弹幕
-(void)createInputView{
GiGaFlingCommitVC* GiGaFlingVC = [[GiGaFlingCommitVC alloc] init];
@@ -89,32 +132,18 @@
}
-(LXCountTimer *)timer{
if (!_timer) {
_timer = [[LXCountTimer alloc] init];
}
return _timer;
}
//滑动手势
-(void)panGestureAction:(UIPanGestureRecognizer *)pan{
CGPoint panLocation = [pan locationInView:self.view];
NSLog(@"panlocation.y:%f",panLocation.y);
if (pan.state == UIGestureRecognizerStateBegan) {
[self animaMask];
// self.attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.faceView attachedToAnchor:self.attachPoint];
// [self.animator addBehavior: self.attachmentBehavior ];
}else if (pan.state == UIGestureRecognizerStateChanged){
// [self.snapBehavior setSnapPoint:self.attachPoint];
// [self.attachmentBehavior setAnchorPoint:panLocation];
}else if (pan.state == UIGestureRecognizerStateEnded){
// [self.animator addBehavior:self.snapBehavior];
// [self.animator removeBehavior:self.attachmentBehavior];
}else{
}
@@ -123,20 +152,21 @@
#pragma mark -开始面膜时间动画
-(void)animaMask{
self.descLabl.hidden = YES;
self.descBackView.hidden = YES;
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.0 animations:^{
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y - 50);
make.top.mas_equalTo(self.attachPoint.y - 118);
}];
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y - 50);
}];
[self.countLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.attachPoint.y + 50 + 10);
make.top.mas_equalTo(self.attachPoint.y -174);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.countLabel.hidden = NO;
self.cicleProgressView.hidden = NO;
self.maskImageView.userInteractionEnabled = NO;
//开始面膜时间
[self startMaskTime];
@@ -146,28 +176,31 @@
#pragma mark 面膜时间结束复原动画
-(void)endMaskAnimation{
self.countLabel.hidden = YES;
self.cicleProgressView.hidden = YES;
self.descLabl.hidden = NO;
self.descBackView.hidden = NO;
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.0 animations:^{
[self.maskImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(100 + 100 + 200);
make.top.mas_equalTo(314 + PhoneX_TopMargin);
}];
[self.faceView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(100);
make.top.mas_equalTo(103 + PhoneX_TopMargin);
}];
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.maskImageView.userInteractionEnabled = YES;
}];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated{
@@ -181,6 +214,7 @@
[self showAPPappGaurdView];
}
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
@@ -196,84 +230,83 @@
[self initUI];
[self addNotify];
[self creatBackGroundMusic];
}
-(void)initUI{
self.view.backgroundColor = GIGARGB(56, 56, 56, 1);
[self.view addSubview:self.maskImageView];
[self.view addSubview:self.faceView];
[self.view bringSubviewToFront:self.maskImageView];
[self.view addSubview:self.countLabel];
//self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
[self.view addSubview:self.descBackView];
[self.view addSubview:self.cicleProgressView];
//face
[self.faceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(100);
make.left.mas_equalTo(self.view.mas_centerX).offset(-50);
make.size.mas_equalTo(CGSizeMake(100, 100));
make.top.mas_equalTo(self.view.mas_top).offset(103 + PhoneX_TopMargin);
make.left.mas_equalTo(self.view.mas_centerX).offset(-69);
make.size.mas_equalTo(CGSizeMake(138, 174));
}];
//mask
[self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(100 + 100 + 200);
make.left.mas_equalTo(self.view.mas_centerX).offset(-50);
make.size.mas_equalTo(CGSizeMake(100, 100));
make.top.mas_equalTo(self.view.mas_top).offset(314 + PhoneX_TopMargin);
make.left.mas_equalTo(self.view.mas_centerX).offset(-51);
make.size.mas_equalTo(CGSizeMake(102, 118));
}];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.view.mas_top).offset(200);
make.width.and.height.mas_equalTo(100);
//描述
[self.descBackView mas_makeConstraints:^(MASConstraintMaker *make){
make.top.mas_equalTo(500 + PhoneX_TopMargin);
make.width.mas_equalTo(149);
make.height.mas_equalTo(45);
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
self.countLabel.hidden = YES;
UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[testBtn setTitle:@"测试肤质" forState:UIControlStateNormal];
[testBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
testBtn.backgroundColor = [UIColor blueColor];
[testBtn addTarget:self action:@selector(testBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
testBtn.layer.masksToBounds = YES;
testBtn.layer.cornerRadius = 4;
[self.view addSubview:testBtn];
[testBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view.mas_centerX);
make.width.mas_equalTo(150);
make.height.mas_equalTo(40);
make.bottom.mas_equalTo(self.view.mas_bottom).offset(-130);
}];
[self.descBackView addSubview:self.descLabl];
[self.descLabl mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(121);
make.height.mas_equalTo(32);
make.center.mas_equalTo(self.descBackView.center);
}];
// UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// [testBtn setTitle:@"测试肤质" forState:UIControlStateNormal];
// [testBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// testBtn.backgroundColor = [UIColor blueColor];
// [testBtn addTarget:self action:@selector(testBtnAcion:) forControlEvents:UIControlEventTouchUpInside];
// testBtn.layer.masksToBounds = YES;
// testBtn.layer.cornerRadius = 4;
// [self.view addSubview:testBtn];
//
// [testBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerX.mas_equalTo(self.view.mas_centerX);
// make.width.mas_equalTo(150);
// make.height.mas_equalTo(40);
// make.bottom.mas_equalTo(self.view.mas_bottom).offset(-130);
// }];
[self.view layoutIfNeeded];
CGFloat Y = CGRectGetMinY(self.maskImageView.frame) - 100;
CGFloat Y = CGRectGetMaxY(self.faceView.frame) + (CGRectGetMaxY(self.maskImageView.frame) - CGRectGetMaxY(self.faceView.frame)) / 2;
CGFloat X = CGRectGetMidX(self.view.frame);
// 下巴合并位置
CGPoint anchorPoint = CGPointMake(X, Y);
self.attachPoint = anchorPoint;
// self.snapBehavior = [[UISnapBehavior alloc] initWithItem:self.maskImageView snapToPoint:self.attachPoint];
}
#pragma mark 开始计时
-(void)countTimeBegain:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second{
long nowTimestamp = [GiGaHelper getNowDateTimestamp];
long futrueTimestamp = [GiGaHelper getFutureTimetstamp:hour minute:minute second:second];
weakify(self);
[self.timer countDownWithStratTimeStamp:nowTimestamp finishTimeStamp:futrueTimestamp completeBlock:^(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second) {
[weakSelf refreshTimeCount:hour minute:minute second:second];
[self.cicleProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(Y + 68);
make.height.and.width.mas_equalTo(136);
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
}
-(void)refreshTimeCount:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
self.countLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minute,second];
if (hour == 0 && minute == 0 && second == 0) {
//面膜结束
[self maskTimeEnd];
}
}
#pragma mark 面膜时间背景音乐
@@ -286,14 +319,14 @@
_musicPalyer = player;
[[AVAudioSession sharedInstance] setActive:YES error:nil];
//设置后台模式和锁屏模式下依然能够播放
//[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
}
#pragma mark 开始面膜时间
-(void)startMaskTime{
[self createInputView]; //出现弹幕
//[self createInputView]; //出现弹幕
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
if (delegate.isMasking) {
return;
@@ -303,17 +336,12 @@
[self setBackGroundPlayingInfo];//锁屏音频信息
//总时间隔 s
NSTimeInterval timeInterVal = 61;
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
NSString *hour = timesArr[0];
NSString *min = timesArr[1];
NSString *sec = timesArr[2];
[self countTimeBegain:hour.integerValue minute:min.integerValue second:sec.integerValue];
NSTimeInterval timeInterVal = 10;
[self.cicleProgressView startWith:timeInterVal];
//底部弹窗
[self showWaringView];
return;
//app 前台时收到本地通知showAlert 后台时通知提醒
[[GiGaLocalNotificationManager localNotifiationCenter] sendLocalNotification:@"本地推送" fireTimeInterval:timeInterVal alertAction:@"测试面膜时间" withIdentifier:kLOCALNotifiID_MASKETIMEEND];
@@ -368,7 +396,7 @@
AppDelegate *delegate =(AppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.isMasking = NO;
[_musicPalyer stop];
[self.timer destoryTimer];
//复原动画
[self endMaskAnimation];
}
@@ -390,8 +418,6 @@
}
}
-(void)addNotify{
NC_ADD_TARGET_NAME_OBJECT(self, @selector(guardViewDissmiss), USER_GUARD_DISSMISS, nil) ;
@@ -465,6 +491,8 @@
[rightBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
[self.navigationController.navigationBar cnSetBackgroundColor:GIGARGB(216, 216, 216, 1)];
}
#pragma mark 消息 action
@@ -494,29 +522,22 @@
#pragma mark -bottomView
-(void)showWaringView{
[UIView animateWithDuration:0.4 animations:^{
self.waringView.frame = CGRectMake(0,self.view.frame.size.height - 60, self.view.frame.size.width, 60);
}];
[self.view addSubview:self.waringView];
weakify(self);
[self.waringView.dismissBtn initWithBlock:^(UIButton *btn) {
NSLog(@"GIGAdismissBtn");
[UIView animateWithDuration:0.4 animations:^{
weakSelf.waringView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.height, 60);
} completion:^(BOOL finished) {
[weakSelf.waringView removeFromSuperview];
}];
} for:UIControlEventTouchUpInside ];
[UIView animateWithDuration:0.4 animations:^{
self.waringView.frame = CGRectMake(0,CGRectGetMaxY(self.view.frame) - 60, self.view.frame.size.width, 60);
}];
[self.waringView showView];
}
- (MaskViewBootomWaringView *)waringView{
#pragma mark - MaskCirCularProGressViewDelegate
if (!_waringView) {
self.waringView = [[MaskViewBootomWaringView alloc] initWithFrame: CGRectMake(0, self.view.frame.size.height, self.view.frame.size.height, 60)];
}
return _waringView;
- (void)updateProgressViewWith:(NSTimeInterval)timeInterval{
}
- (void)progressDidFish{
NSLog(@"结束");
[self maskTimeEnd];
}
- (void)didReceiveMemoryWarning {
@@ -0,0 +1,39 @@
//
// MaskTimeCircularProgressView.h
// GIGA
//
// Created by lianxiang on 2018/9/3.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "SHineLabel.h"
@protocol MaskCirCularProGressViewDelegate<NSObject>
@optional
-(void)updateProgressViewWith:(NSTimeInterval)timeInterval;
-(void)updateProgress;
-(void)progressDidFish;
@end
@interface MaskTimeCircularProgressView : UIView
@property(nonatomic,weak) id<MaskCirCularProGressViewDelegate>delegate;
@property(nonatomic) UIColor *backColor;
@property(nonatomic) UIColor *progressColor;
@property(nonatomic,strong) UILabel *countDownLabel;
@property(nonatomic) NSTimeInterval timeinterval;
@property(nonatomic) CGFloat lineWidth;
@property(nonatomic) BOOL isMoving;
@property (nonatomic,strong) SHineLabel *countLabel;
-(id)initWithFrame:(CGRect)frame
backColor:(UIColor *)backColor
progressColor:(UIColor *)progressColor
lineWidth:(CGFloat)lineWidth
timeinterval:(NSTimeInterval)timeinterval;
-(void)startWith:(NSTimeInterval)time;
-(void)stop;
-(void)pasuse;
@end
@@ -0,0 +1,261 @@
//
// MaskTimeCircularProgressView.m
// GIGA
//
// Created by lianxiang on 2018/9/3.
// Copyright © 2018年 com.giga.ios. All rights reserved.
//
#import "MaskTimeCircularProgressView.h"
#import "LXCountTimer.h"
#import "SHineLabel.h"
@interface MaskTimeCircularProgressView()
@property (nonatomic) CADisplayLink *displayLink;
@property (nonatomic) CAShapeLayer *progressLayer;
@property (nonatomic) float progress;
@property (nonatomic) CGFloat angle;
@property (nonatomic) NSTimeInterval currentTimeinterval;
@property (nonatomic,strong) LXCountTimer *timer;
@property (nonatomic,strong) NSTimer *playTimer;
@end
@implementation MaskTimeCircularProgressView
- (id)initWithFrame:(CGRect)frame backColor:(UIColor *)backColor progressColor:(UIColor *)progressColor lineWidth:(CGFloat)lineWidth timeinterval:(NSTimeInterval)timeinterval
{
self = [super initWithFrame:frame];
if (self) {
_backColor = backColor;
_progressColor = progressColor;
self.lineWidth = lineWidth;
self.timeinterval = timeinterval;
[self setUP];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
[self setUP];
}
return self;
}
-(void)setUP{
self.backgroundColor = [UIColor clearColor];
_currentTimeinterval = 0;
_isMoving = NO;
self.countLabel.frame = CGRectMake(_lineWidth, self.frame.size.height /2 - 15 , self.frame.size.width - _lineWidth*2, 30);
[self addSubview:self.countLabel];
}
-(LXCountTimer *)timer{
if (!_timer) {
_timer = [[LXCountTimer alloc] init];
}
return _timer;
}
- (NSTimer *)playTimer{
if (!_playTimer) {
_playTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(payCircular) userInfo:nil repeats:YES];
}
return _playTimer;
}
//倒计时label
-(SHineLabel *)countLabel{
if (!_countLabel) {
_countLabel = [[SHineLabel alloc] init];
_countLabel.outLineColor = [UIColor whiteColor];
_countLabel.blurColor = [UIColor whiteColor];
_countLabel.oinsideColor = [UIColor whiteColor];
_countLabel.text = @"00:00";
_countLabel.font = [UIFont fontWithName:GIGA_FONTBOLD size:22];
}
return _countLabel;
}
- (void)setLineWidth:(CGFloat)lineWidth{
CAShapeLayer *backgroundLayer = [self createRingLayerWithCenter:CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2) radius:CGRectGetWidth(self.bounds) / 2 - lineWidth / 2 lineWidth:lineWidth color:self.backColor];
_lineWidth = lineWidth;
[self.layer addSublayer:backgroundLayer];
_progressLayer = [self createRingLayerWithCenter:CGPointMake(CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame) / 2) radius:CGRectGetWidth(self.bounds) / 2 - lineWidth / 2 lineWidth:lineWidth color:self.progressColor];
_progressLayer.strokeEnd = 0;
[self.layer addSublayer:_progressLayer];
//渐变色
CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height;
CALayer *gradientLayer = [CALayer layer];
gradientLayer.frame = self.bounds;
CAGradientLayer *gradientLayer1 = [CAGradientLayer layer];
gradientLayer1.frame = CGRectMake(0, 0, width, height);
gradientLayer1.colors = @[(__bridge id) [UIColor colorWithRed:151/255.0 green:253/255.0 blue:255/255.0 alpha:1/1.0].CGColor,(__bridge id)[UIColor colorWithRed:165/255.0 green:81/255.0 blue:216/255.0 alpha:1/1.0].CGColor];
//纵向变化
gradientLayer1.startPoint = CGPointMake(0.5, 0);
gradientLayer1.endPoint = CGPointMake(0.5, 1);
[gradientLayer addSublayer:gradientLayer1];
[self.layer addSublayer:gradientLayer];
gradientLayer.mask = _progressLayer ;
}
- (CAShapeLayer *)createRingLayerWithCenter:(CGPoint)center radius:(CGFloat)radius lineWidth:(CGFloat)lineWidth color:(UIColor *)color {
UIBezierPath *smoothedPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius startAngle:- M_PI_2 endAngle:(M_PI + M_PI_2) clockwise:YES];
CAShapeLayer *slice = [CAShapeLayer layer];
slice.contentsScale = [[UIScreen mainScreen] scale];
slice.frame = CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2);
slice.fillColor = [UIColor clearColor].CGColor;
slice.strokeColor = color.CGColor;
slice.lineWidth = lineWidth;
slice.lineCap = kCALineJoinRound;
slice.lineJoin = kCALineJoinBevel;
slice.path = smoothedPath.CGPath;
return slice;
}
- (void)setProgress:(float)progress{
if (progress == 0) {
self.progressLayer.hidden = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.progressLayer.strokeEnd = 0;
});
}else {
self.progressLayer.hidden = NO;
self.progressLayer.strokeEnd = progress;
}
}
- (void)updateProgressCircle{
//update progress value
self.progress = (float) (self.currentTimeinterval / self.timeinterval);
if (self.delegate && [self.delegate conformsToProtocol:@protocol(MaskCirCularProGressViewDelegate)]) {
//self.countLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minute,second];
[self.delegate updateProgressViewWith:self.currentTimeinterval];
}
}
-(void)payCircular{
self.currentTimeinterval += 0.01;
}
- (void)startWith:(NSTimeInterval)time{
self.timeinterval = time;
[self countDown:time];
[self start];
}
-(void)start{
[[NSRunLoop mainRunLoop] addTimer:self.playTimer forMode:NSRunLoopCommonModes];
if (!self.isMoving) {
if (!self.displayLink) {
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateProgressCircle)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}else {
self.displayLink.paused = NO;
}
self.isMoving = YES;
}
}
-(void)countDown:(NSTimeInterval)timeInterVal{
NSString *timeformat = [GiGaHelper stringWithNSTimerinterval:timeInterVal];
NSArray *timesArr = [timeformat componentsSeparatedByString:@":"];
NSString *hour = timesArr[0];
NSString *min = timesArr[1];
NSString *sec = timesArr[2];
[self countTimeBegain:hour.integerValue minute:min.integerValue second:sec.integerValue];
}
#pragma mark 开始计时
-(void)countTimeBegain:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second{
long nowTimestamp = [GiGaHelper getNowDateTimestamp];
long futrueTimestamp = [GiGaHelper getFutureTimetstamp:hour minute:minute second:second];
weakify(self);
[self.timer countDownWithStratTimeStamp:nowTimestamp finishTimeStamp:futrueTimestamp completeBlock:^(NSInteger day, NSInteger hour, NSInteger minute, NSInteger second) {
[weakSelf refreshTimeCount:hour minute:minute second:second];
}];
}
-(void)refreshTimeCount:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second{
self.countLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minute,second];
if (hour == 0 && minute == 0 && second == 0) {
//面膜结束
//[self maskTimeEnd];
[self.timer destoryTimer];
[self.playTimer invalidate];
self.playTimer = nil;
[self stop];
if (self.delegate && [self.delegate conformsToProtocol:@protocol(MaskCirCularProGressViewDelegate)]) {
[self.delegate progressDidFish];
}
}
}
-(void)pasuse{
if (self.isMoving) {
self.displayLink.paused = YES;
self.isMoving = NO;
}
}
-(void)stop{
self.isMoving = NO;
self.progress = 0 ;
self.currentTimeinterval = 0;
[self.displayLink invalidate];
self.displayLink = nil;
}
//calculate angle between start to point
- (CGFloat)angleFromStartToPoint:(CGPoint)point{
CGFloat angle = [self angleBetweenLinesWithLine1Start:CGPointMake(CGRectGetWidth(self.bounds) / 2,CGRectGetHeight(self.bounds) / 2)
Line1End:CGPointMake(CGRectGetWidth(self.bounds) / 2,CGRectGetHeight(self.bounds) / 2 - 1)
Line2Start:CGPointMake(CGRectGetWidth(self.bounds) / 2,CGRectGetHeight(self.bounds) / 2)
Line2End:point];
if (CGRectContainsPoint(CGRectMake(0, 0, CGRectGetWidth(self.frame) / 2, CGRectGetHeight(self.frame)), point)) {
angle = 2 * M_PI - angle;
}
return angle;
}
//calculate angle between 2 lines
- (CGFloat)angleBetweenLinesWithLine1Start:(CGPoint)line1Start
Line1End:(CGPoint)line1End
Line2Start:(CGPoint)line2Start
Line2End:(CGPoint)line2End{
CGFloat a = line1End.x - line1Start.x;
CGFloat b = line1End.y - line1Start.y;
CGFloat c = line2End.x - line2Start.x;
CGFloat d = line2End.y - line2Start.y;
return acos(((a * c) + (b * d)) / ((sqrt(a * a + b * b)) * (sqrt(c * c + d * d))));
}
@end
@@ -11,5 +11,6 @@
@interface MaskViewBootomWaringView : UIView
@property(nonatomic,strong) GiGaBlockButton *dismissBtn;
-(void)showView;
@end
@@ -38,12 +38,13 @@
waringLabel.text = @"亲爱滴,请您务必要开启手机声音哦";
waringLabel.textColor = [UIColor whiteColor];
waringLabel.textAlignment = NSTextAlignmentCenter;
waringLabel.font = [UIFont systemFontOfSize:16];
[waringLabel sizeToFit];
waringLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:waringLabel];
[waringLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(iconImg.mas_right).offset(10);
make.left.mas_equalTo(self.mas_left).offset(40);
make.right.mas_equalTo(self.mas_right).offset(-40);
make.centerY.mas_equalTo(self.mas_centerY);
}];
@@ -61,5 +62,20 @@
}];
}
-(void)showView{
[self.dismissBtn initWithBlock:^(UIButton *btn) {
[UIView animateWithDuration:0.4 animations:^{
self.frame = CGRectMake(0, KMainH, KMainW, 60);
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
} for:UIControlEventTouchUpInside ];
}
@end