Advertisement
Guest User

Untitled

a guest
Aug 26th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "arcView.h"
  2. #import <QuartzCore/QuartzCore.h>
  3.  
  4. @implementation arcView
  5.  
  6. - (id)initWithFrame:(CGRect)frame
  7. {
  8.     self = [super initWithFrame:frame];
  9.     if (self) {
  10.         self.layer.contents = (__bridge id)([[self generateArc]CGImage]);
  11.     }
  12.     return self;
  13. }
  14. -(UIImage*)generateArc{
  15.     UIGraphicsBeginImageContext(self.frame.size);
  16.     CGContextRef context = UIGraphicsGetCurrentContext();
  17.     CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1);
  18.     CGContextSetLineWidth(context, 2);
  19.     CGContextSetLineCap(context, kCGLineCapButt);
  20.     CGContextAddArc(context,
  21.                     self.frame.size.height/2, self.frame.size.height/2,
  22.                     self.frame.size.height/2 - 2,0.0,M_PI_4,NO);
  23.     CGContextStrokePath(context);
  24.     UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
  25.     UIGraphicsEndImageContext();
  26.  
  27.     return result;
  28. }
  29. -(void)animate{
  30.     CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"rotation"];
  31.     rotate.fromValue = [NSNumber numberWithFloat:0];
  32.     rotate.toValue = [NSNumber numberWithFloat:360];
  33.     rotate.duration = 1.0;
  34.     rotate.repeatCount = 999999;
  35.     rotate.fillMode = kCAFillModeForwards;
  36.     rotate.removedOnCompletion = NO;
  37.     [self.layer addAnimation:rotate forKey:@"rotation"];
  38. }
  39. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement