Last active
August 29, 2015 14:21
-
-
Save yuanshanxiaoni/4cce40c54114a91cf42a to your computer and use it in GitHub Desktop.
shineCircles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "ViewController.h" | |
| @interface ViewController () | |
| @property (weak, nonatomic) IBOutlet UIView *yellowView; | |
| @property (weak, nonatomic) IBOutlet UIImageView *imageView; | |
| @end | |
| @implementation ViewController | |
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| self.view.backgroundColor = [UIColor blackColor]; | |
| // UIImage *img = [UIImage imageNamed:@"head.png" ]; | |
| // _yellowView.layer.contents = (__bridge id)img.CGImage; | |
| NSLog(@"keys : %@", _yellowView.layer.animationKeys); | |
| _yellowView.layer.cornerRadius = _yellowView.bounds.size.width/2; | |
| _yellowView.layer.masksToBounds = YES; | |
| // _imageView.layer.cornerRadius = _yellowView.bounds.size.width/2 ; | |
| // _imageView.layer.masksToBounds = YES; | |
| CAShapeLayer *layer = [CAShapeLayer layer]; | |
| layer.lineWidth = 2.0f; | |
| layer.fillColor = NULL; | |
| layer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(_imageView.bounds, 0, 0)].CGPath; | |
| layer.strokeColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.8].CGColor; | |
| layer.contentsScale = [UIScreen mainScreen].scale * 2; | |
| layer.shadowOffset = CGSizeZero; | |
| layer.shadowOpacity = 0; | |
| layer.shadowRadius = 4; | |
| layer.shadowColor = [UIColor whiteColor].CGColor; | |
| layer.shouldRasterize = NO; | |
| [_imageView.layer addSublayer:layer]; | |
| [self shineAnimationAddto:layer]; | |
| } | |
| - (void)pluseAnimationAddto:(CALayer *)layer { | |
| CIFilter *filter = [CIFilter filterWithName:@"CIFalseColor"]; | |
| [filter setDefaults]; | |
| [filter setValue:[CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] forKey:@"inputColor0"]; | |
| [filter setValue:[CIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0] forKey:@"inputColor1"]; | |
| // [filter setName:@"pulseFilter"]; | |
| [layer setFilters:[NSArray arrayWithObject:filter]]; | |
| CABasicAnimation* pulseAnimation = [CABasicAnimation animation]; | |
| pulseAnimation.keyPath = @"filters.pulseFilter.inputColor1"; | |
| pulseAnimation.fromValue = [CIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; | |
| pulseAnimation.toValue = [CIColor colorWithRed:0.995 green:1.0 blue:0.655 alpha:1.0]; | |
| pulseAnimation.duration = 0.3; | |
| pulseAnimation.repeatCount = 1; | |
| pulseAnimation.autoreverses = YES; | |
| [ layer addAnimation:pulseAnimation forKey:@"pulseAnimation"]; | |
| } | |
| - (void)shineAnimationAddto:(CALayer *)layer { | |
| CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"]; | |
| anim.fromValue = @0; | |
| anim.toValue = @1; | |
| anim.repeatCount = NSIntegerMax; | |
| anim.autoreverses = YES; | |
| anim.duration = 2.0; | |
| anim.timingFunction = | |
| [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
| [layer addAnimation:anim forKey:@"shine"]; | |
| } | |
| /* | |
| - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { | |
| CGContextRef context = ctx; | |
| // circumscribe the polygons | |
| CGContextSetLineWidth(context, 2); // set the line width | |
| CGContextSetRGBStrokeColor(context, 20.0 /255, 101.0 / 255.0, 18.0 / 255.0, 1.0); | |
| CGRect rect = self.yellowView.frame; | |
| CGPoint center = CGPointMake(rect.size.width / 2, rect.size.height / 2); // get the circle centre | |
| CGFloat radius = 0.9 * center.x; // little scaling needed | |
| CGFloat startAngle = -((float)M_PI / 2); // 90 degrees | |
| CGFloat endAngle = ((2 * (float)M_PI) + startAngle); | |
| CGContextAddArc(context, center.x, center.y, radius + 4, startAngle, endAngle, 0); // create an arc the +4 just adds some pixels because of the polygon line thickness | |
| CGContextStrokePath(context); // draw | |
| // inscribed circle | |
| float angle = M_PI - ((2 * M_PI) / 4);//polygon.numberOfSides); // need the polygon angles | |
| CGContextSetLineWidth(context, 2); // set the line width | |
| CGContextSetRGBStrokeColor(context, 20.0 / 255, 101.0 / 255.0, 211.0 / 255.0, 1.0); | |
| CGFloat innerradius = (0.9 * center.x) * sin(angle / 2); // calc the inner radius | |
| CGContextAddArc(context, center.x, center.y, innerradius - 3, startAngle, endAngle, 0); // create an arc the minus 3 subtracts some pixels because of the polygon line thickness | |
| CGContextStrokePath(context); // draw | |
| }*/ | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment