iOS 开机滑动解锁

这里写图片描述

直接上代码

//// UIView+FlashesMask.h// RunningLightAnimation
//// Created by iFens on 16/3/29.// Copyright © 2016年 Ifans. All rights reserved.
//#import <UIKit/UIKit.h>@interface UIView (FlashesMask)
-(void)FlashesMaskAimationBeginWithRepeatCount:(CGFloat)count duration:(NSTimeInterval)duration FlashesWidth:(CGFloat)FlashesWidth ;
-(void)FlashesMaskAimationStop;
@end
//// UIView+FlashesMask.m// RunningLightAnimation
//// Created by iFens on 16/3/29.// Copyright © 2016年 Ifans. All rights reserved.
//#import "UIView+FlashesMask.h"
#define FlashesMaskAinmation @"FlashesMaskAinmation"
@implementation UIView (FlashesMask)-(void)FlashesMaskAimationBeginWithRepeatCount:(CGFloat)count duration:(NSTimeInterval)duration FlashesWidth:(CGFloat)FlashesWidth
{ NSAssert([self isKindOfClass:[UIView class]], @"必须是UIView子类");  
CAGradientLayer *FlashesMaskLayer = [[CAGradientLayer alloc]init]; 
[FlashesMaskLayer setFrame:self.bounds]; CGFloat flashSize = FlashesWidth / self.frame.size.width;
  NSArray *startLocations = @[@0, [NSNumber numberWithFloat:(flashSize / 2.)], [NSNumber numberWithFloat:flashSize] ]; 
NSArray *endLocations = @[[NSNumber numberWithFloat:(1. - flashSize)], 
[NSNumber numberWithFloat:(1. - (flashSize / 2.))], @1 ];  
FlashesMaskLayer.locations = startLocations; FlashesMaskLayer.startPoint = CGPointMake(0 - (flashSize * 2), .5);
 FlashesMaskLayer.endPoint = CGPointMake(1 + flashSize, .5); 
[FlashesMaskLayer setColors:@[(id)[UIColor colorWithWhite:1 alpha:0.1].CGColor,(id)[UIColor colorWithWhite:0 alpha:1].CGColor,(id)[UIColor colorWithWhite:1 alpha:0.1].CGColor]];
 CABasicAnimation * base = [CABasicAnimation animationWithKeyPath:@"locations"];
 base.fromValue = startLocations; base.toValue = endLocations;
  [base setDuration:duration];
 [base setRepeatCount:count]; self.layer.mask=FlashesMaskLayer; 
[FlashesMaskLayer addAnimation:base forKey:FlashesMaskAinmation];}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ if (
[anim valueForKey:FlashesMaskAinmation]) { self.layer.mask = nil; 
}}

-(void)FlashesMaskAimationStop{ 
[self.layer.mask removeAnimationForKey:FlashesMaskAinmation];
}
@end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容