Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "arcView.h"
- #import <QuartzCore/QuartzCore.h>
- @implementation arcView
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.layer.contents = (__bridge id)([[self generateArc]CGImage]);
- }
- return self;
- }
- -(UIImage*)generateArc{
- UIGraphicsBeginImageContext(self.frame.size);
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1);
- CGContextSetLineWidth(context, 2);
- CGContextSetLineCap(context, kCGLineCapButt);
- CGContextAddArc(context,
- self.frame.size.height/2, self.frame.size.height/2,
- self.frame.size.height/2 - 2,0.0,M_PI_4,NO);
- CGContextStrokePath(context);
- UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return result;
- }
- -(void)animate{
- CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"rotation"];
- rotate.fromValue = [NSNumber numberWithFloat:0];
- rotate.toValue = [NSNumber numberWithFloat:360];
- rotate.duration = 1.0;
- rotate.repeatCount = 999999;
- rotate.fillMode = kCAFillModeForwards;
- rotate.removedOnCompletion = NO;
- [self.layer addAnimation:rotate forKey:@"rotation"];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement