Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // LSCircleView.m
- // LEE Stopper App
- //
- // Created by admin on 10.02.16.
- // Copyright © 2016 1. All rights reserved.
- //
- #import "LSCircleView.h"
- #import "LSTouchGestureRecognizer.h"
- @implementation LSCircleView
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- */
- static double distanceAngleRatio=0.0035;
- -(id) initWithFrame:(CGRect)frame
- {
- if (self = [super initWithFrame:frame])
- {
- NSString *clickSoundPath = [[NSBundle mainBundle] pathForResource:@"click_soft_tap" ofType:@"aif"];
- AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: clickSoundPath], &_clickSoundID);
- }
- return self;
- }
- -(void) initWith:(UIColor*) dividersColor labelTexts:(NSArray*)labelTexts
- {
- _activeDividerIndex=-1;
- //if(_radius == 0)
- [self calculateRadiusAndCenter];
- _dividersArray=[NSMutableArray array];
- _dividersView = [[UIView alloc] init];
- _dividersView.layer.anchorPoint=CGPointMake(0.5, 0.5);
- _dividersView.frame=CGRectMake(0,0, 2*_radius,2*_radius);
- _dividersView.center = CGPointMake(_center.x, _center.y);
- //_dividersView.backgroundColor=[UIColor redColor];
- [self addSubview:_dividersView];
- int dividersCount = 19;
- int partsPerDivider = 3;
- float angleStep = 2*M_PI/dividersCount;
- _rotationStep = angleStep / partsPerDivider;
- float startAngle = self.mirrored ? M_PI : 0;
- float direction = self.mirrored ? -1 : 1;
- float bigDividerLength = 19;
- float smallDividerLength = 10;
- CGPoint localCelnter = CGPointMake(_radius,_radius);
- for(int i=0;i<dividersCount;i++)
- {
- float angle = startAngle + direction * angleStep * i;
- float x = localCelnter.x + (_radius - bigDividerLength/2) * cos(angle);
- float y = localCelnter.y + (_radius - bigDividerLength/2) * sin(angle);
- UIView * divider = [[UIView alloc] initWithFrame:CGRectMake(0, 0, bigDividerLength, 0)];
- [UIView animateWithDuration:0.2 animations:^{
- divider.frame=CGRectMake(0, 0, bigDividerLength, 2);
- }];
- divider.backgroundColor=dividersColor;
- divider.alpha=0.3;
- divider.center = CGPointMake(x, y);
- divider.transform = CGAffineTransformMakeRotation(angle);
- [_dividersView addSubview:divider];
- [_dividersArray addObject:divider];
- UILabel * label = [[UILabel alloc] init];
- label.font=[UIFont fontWithName:@"Roboto Condensed" size:25];
- label.textColor=dividersColor;
- //label.backgroundColor=[UIColor redColor];
- label.text=labelTexts[i*3];//[NSString stringWithFormat:@"%d",i]; ////
- label.numberOfLines=0;
- [label sizeToFit];
- //label.layer.anchorPoint=CGPointMake(0.5, 0.5);
- [_dividersView addSubview:label];
- //label.center = CGPointMake(x - label.frame.size.width/2, y);
- float labelX = localCelnter.x + (_radius - label.frame.size.width/2 - bigDividerLength -5) * cos(angle);
- float labelY = localCelnter.y + (_radius - label.frame.size.width/2 - bigDividerLength -5) * sin(angle);
- label.frame=CGRectMake(labelX,labelY, label.frame.size.width, label.frame.size.height);
- label.center=CGPointMake(labelX, labelY);
- label.transform= CGAffineTransformMakeRotation(angle);
- label.alpha=0;
- if(self.mirrored)
- label.transform= CGAffineTransformMakeRotation(angle - M_PI );
- [UIView animateWithDuration:0.2 animations:^{
- label.alpha=1;
- }];
- // Add small dividers
- if(i != dividersCount-1)
- for (int j=0;j<2;j++)
- {
- float smallAngle = angle + direction * (j+1)*angleStep/partsPerDivider;
- x = localCelnter.x + (_radius - smallDividerLength/2) * cos(smallAngle);
- y = localCelnter.y + (_radius - smallDividerLength/2) * sin(smallAngle);
- UIView * smallDivider = [[UIView alloc] initWithFrame:CGRectMake(0, 0, smallDividerLength, 0)];
- [UIView animateWithDuration:0.2 animations:^{
- smallDivider.frame=CGRectMake(0, 0, smallDividerLength, 1);
- }];
- smallDivider.backgroundColor=dividersColor;
- smallDivider.alpha=0.3;
- smallDivider.center = CGPointMake(x, y);
- smallDivider.transform = CGAffineTransformMakeRotation(smallAngle);
- [_dividersView addSubview:smallDivider];
- [_dividersArray addObject:smallDivider];
- }
- }
- // Gesture recognition
- /*
- LSTouchGestureRecognizer *touchDown = [[LSTouchGestureRecognizer alloc] initWithTarget:self action:@selector(handleTouchDown:)];
- touchDown.delegate=self;
- touchDown.cancelsTouchesInView=NO;
- touchDown.delaysTouchesBegan=NO;
- touchDown.delaysTouchesEnded=NO;
- [self addGestureRecognizer:touchDown];
- */
- self.userInteractionEnabled=YES;
- UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
- pan.delegate=self;
- pan.cancelsTouchesInView=YES;
- pan.delaysTouchesBegan=NO;
- pan.delaysTouchesEnded=NO;
- [self addGestureRecognizer:pan];
- [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(updateMethod) userInfo:nil repeats:YES];
- }
- -(void) deativatePanIfNeeded
- {
- _shouldSendDelegateUpdates=NO;
- _dividersView.layer.transform = [(CALayer*)_dividersView.layer.presentationLayer transform];
- [CATransaction begin];
- [_dividersView.layer removeAllAnimations];
- [CATransaction commit];
- }
- -(void) hideDividers
- {
- _dividersView.alpha=0;
- }
- -(void) showDividers
- {
- _dividersView.alpha=1;
- }
- -(void) rotateManuallyTo:(double)rotation
- {
- _changedRotation=YES;
- _dividersView.transform=CGAffineTransformMakeRotation(rotation);
- }
- -(void) updateMethod
- {
- [self updateDividersIfNeeded];
- //NSLog(@"_shouldSendDelegateUpdates = %d",_shouldSendDelegateUpdates);
- /*
- if(!_shouldSendDelegateUpdates)
- return;
- float curAngle = [(NSNumber *)[_dividersView.layer.presentationLayer valueForKeyPath:@"transform.rotation.z"] floatValue];
- ;
- [self.delegate circleView:self didRotateTo:curAngle];
- */
- }
- #pragma mark - Gesture Recognition
- -(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- //float startAngle = atan2(_dividersView.transform.b, _dividersView.transform.a);
- //_dividersView.layer.speed = 0;
- [self.delegate circleViewDidTouchBegan:self];
- [self stopAnimation];
- }
- -(void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- if(_isPanning)
- return;
- [self rotateAnimatedWithVelocity:0];
- }
- -(void) touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
- {
- [self touchesEnded:touches withEvent:event];
- }
- -(void) stopAnimation
- {
- _dividersView.layer.transform = [(CALayer*)_dividersView.layer.presentationLayer transform];
- [CATransaction begin];
- [_dividersView.layer removeAllAnimations];
- [CATransaction commit];
- }
- -(void) panHandler:(UIPanGestureRecognizer*)sender
- {
- _changedRotation=YES;
- static double startAngle;
- static double lastChange=0;
- CGPoint translatedPoint = [sender translationInView:sender.view];
- CGPoint velocity=[sender velocityInView:sender.view];
- if ( sender.state == UIGestureRecognizerStateChanged )
- lastChange = CFAbsoluteTimeGetCurrent();
- /*
- if(previousDate)
- {
- float seconds = [curDate timeIntervalSinceDate:previousDate];
- float yDelta = translatedPoint.y - previousLocation.y;
- velocity =CGPointMake(0, yDelta/seconds);
- NSLog(@"vel %f actual %f",velocity.y,[sender velocityInView:sender.view].y);
- }
- if(sender.state == UIGestureRecognizerStateEnded)
- velocity = previousVelocity;
- previousDate=curDate;
- previousLocation=translatedPoint;
- previousVelocity = velocity;
- */
- if(sender.state == UIGestureRecognizerStateBegan)
- {
- startAngle = atan2(_dividersView.transform.b, _dividersView.transform.a);
- // Hack to prefent floating error
- //int steps = startAngle / _rotationStep;
- //startAngle = steps * _rotationStep;
- _isPanning = YES;
- }
- if(sender.state == UIGestureRecognizerStateEnded)
- {
- //_dividersView.layer.speed=1;
- //NSLog(@"\n\n\n\n\n\n\n\n\n\n");
- //if(curAngle<0)
- // curAngle = + 2*M_PI;
- float vY = velocity.y;
- double curTime = CFAbsoluteTimeGetCurrent();
- double timeElapsed = curTime - lastChange;
- if ( timeElapsed > 0.02 )
- vY = 0;
- //NSLog(@"TIME %f %f",timeElapsed,vY);
- if(fabs(vY)<200)
- vY=0;
- [self rotateAnimatedWithVelocity:vY];
- //NSLog(@"delta %f", delta);
- //NSLog(@"%f === %f", (curAngle - delta) / _rotationStep , atan2(_dividersView.transform.b, _dividersView.transform.a)/ _rotationStep );
- _isPanning = NO;
- return;
- }
- int direction = self.mirrored? -1:1;
- float newRotation = startAngle + direction * translatedPoint.y * distanceAngleRatio;
- _dividersView.transform=CGAffineTransformMakeRotation(newRotation);
- [self.delegate circleView:self didRotateTo:newRotation];
- [self updateDividersIfNeeded];
- }
- -(void) rotateAnimatedWithVelocity:(float) vY
- {
- int velDirection = vY/fabs(vY);
- if(vY ==0)
- velDirection=0;
- if(!self.mirrored)
- velDirection = - velDirection;
- float curAngle = atan2(_dividersView.transform.b, _dividersView.transform.a);
- int angleSign = curAngle / fabs(curAngle);
- double delta = fabs(vY);//MIN(fabs(vY),3600);
- float distanceAngleRatio_ = 0.03;
- delta = delta * (distanceAngleRatio_ * 20);
- delta = delta / 180;
- //delta = delta;
- double stepsF = (curAngle - velDirection * delta) / _rotationStep;
- int steps = (int)(stepsF + angleSign * 0.5);
- //NSLog(@"stepsF = %f, steps = %d, vY = %f",stepsF,steps,vY);
- //NSLog(@"velDirection %d",velDirection);
- float duration=2.0;
- if(velDirection == 0)
- {
- velDirection=angleSign;
- duration=0.3;
- }
- if(angleSign >0)
- {
- delta = -velDirection * (steps*_rotationStep - curAngle);
- }
- else
- {
- delta = -velDirection * (-steps*_rotationStep + curAngle);
- }
- // float durationStep=duration / (delta / M_PI_2);
- int animateDirection = - angleSign * velDirection;
- [self.delegate circleView:self didAnimateByAngle:delta inDirection:animateDirection withDuration:duration];
- [self animateRotationDividersViewByAngle:delta inDirection:animateDirection duration:duration];
- }
- -(void)animateRotationDividersViewByAngle:(double)angle inDirection:(int)direction duration:(float)duration
- {
- /*
- double restOfTheRotation = angle - M_PI_2;
- double angleToRotate = M_PI_2;
- NSInteger easing = UIViewAnimationOptionCurveLinear;
- if(restOfTheRotation<=0)
- {
- easing = UIViewAnimationOptionCurveEaseOut;
- angleToRotate=angle;
- }
- float duration = durationStep * angleToRotate / M_PI_2;
- [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionAllowUserInteraction|easing animations:^{
- [_dividersView setTransform:CGAffineTransformRotate(_dividersView.transform, direction * angleToRotate)];
- }completion:^(BOOL finished){
- if (finished) {
- if(restOfTheRotation>0)
- [self animateRotationDividersViewByAngle:restOfTheRotation inDirection:direction durationStep:durationStep];
- else
- {
- //_shouldSendDelegateUpdates=NO;
- }
- }
- //NSLog(@"finished %f",atan2(_dividersView.transform.b, _dividersView.transform.a));
- }];
- */
- /*
- CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- rotationAnimation.fromValue=[_dividersView.layer valueForKeyPath:@"transform.rotation.z"];
- rotationAnimation.toValue = @(direction == 1 ? angle : -angle);
- rotationAnimation.duration = 2.0;
- rotationAnimation.autoreverses = NO;
- // rotationAnimation.repeatCount = repeatCount;
- rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- [_dividersView.layer addAnimation:rotationAnimation
- forKey:@"transform.rotation.z"];
- */
- _prevRotationDuration=duration;
- _prevRotationDirection=direction;
- _prevRotationAngle=angle;
- double deltaAngle = direction * angle;
- _backRotationAngle = deltaAngle / 20.0;
- int backAngleSign = _backRotationAngle/ fabs(_backRotationAngle);
- _backRotationAngle = backAngleSign * MIN(0.1, fabs(_backRotationAngle));
- //NSLog(@"back %f",_backRotationAngle);
- CALayer * myLayer = _dividersView.layer;
- NSNumber *rotationAtStart = [myLayer valueForKeyPath:@"transform.rotation.z"];
- CATransform3D myRotationTransform = CATransform3DRotate(myLayer.transform, deltaAngle + _backRotationAngle, 0.0, 0.0, 1.0);
- myLayer.transform = myRotationTransform;
- CABasicAnimation *myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- myAnimation.duration = duration;
- myAnimation.fromValue = rotationAtStart;
- myAnimation.toValue = [NSNumber numberWithFloat:([rotationAtStart floatValue] + deltaAngle + _backRotationAngle)];
- myAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
- //myAnimation.timingFunction=[CAMediaTimingFunction functionWithControlPoints:.0 :1.2 :1 :1];
- myAnimation.delegate=self;
- [myLayer addAnimation:myAnimation forKey:@"transform.rotation.z"];
- }
- - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
- {
- if(!flag)
- return;
- //NSLog(@"Angele = %f",_prevRotationAngle/20.0);
- CALayer * myLayer = _dividersView.layer;
- NSNumber *rotationAtStart = [myLayer.presentationLayer valueForKeyPath:@"transform.rotation.z"];
- CATransform3D myRotationTransform = CATransform3DRotate(myLayer.transform,-_backRotationAngle, 0.0, 0.0, 1.0);
- myLayer.transform = myRotationTransform;
- CABasicAnimation *myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- myAnimation.duration = _prevRotationDuration/5.0;
- myAnimation.fromValue = rotationAtStart;
- myAnimation.toValue = [NSNumber numberWithFloat:([rotationAtStart floatValue] - _backRotationAngle)];
- myAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
- // myAnimation.timingFunction=[CAMediaTimingFunction functionWithControlPoints:.0 :1.2 :1 :1];
- [myLayer addAnimation:myAnimation forKey:@"transform.rotation.z"];
- }
- /*
- -(void) panHandler:(UIPanGestureRecognizer*)sender
- {
- static CGPoint startPos;
- static double startAngle;
- static double distanceAngleRatio=0.007;
- static int draggedStepsCount;
- CGPoint translatedPoint = [sender locationInView:sender.view];
- CGPoint velocity = [sender velocityInView:sender.view];
- if(sender.state == UIGestureRecognizerStateBegan)
- {
- startPos = translatedPoint;
- startAngle = atan2(_dividersView.transform.b, _dividersView.transform.a);
- // Hack to prefent floating error
- int steps = startAngle / _rotationStep;
- startAngle = steps * _rotationStep;
- draggedStepsCount = 0;
- }
- int direction = self.mirrored? -1 : 1;
- double dist = translatedPoint.y - startPos.y;
- dist = dist * distanceAngleRatio;
- int steps= dist/_rotationStep;
- double newRotatation=startAngle + direction * steps * _rotationStep;
- if(sender.state == UIGestureRecognizerStateEnded)
- {
- float vY = velocity.y;
- int velDirection = -velocity.y/fabs(velocity.y);
- float delta = MIN(fabs(vY),1790);
- delta = delta/10;
- delta = delta / 180;
- delta = delta * velDirection;
- NSLog(@"%f %f",delta,vY);
- [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
- _dividersView.transform=CGAffineTransformMakeRotation(newRotatation + delta);
- } completion:nil];
- }
- if(steps != draggedStepsCount)
- {
- NSInteger activeDividerNumber = [self calculateDividerIndexBasedOnRotation:newRotatation];
- ///////////////////
- _dividersView.transform=CGAffineTransformMakeRotation(newRotatation);
- draggedStepsCount = steps;
- [self updateDividers:newRotatation];
- [self.delegate circleView:self didRotateTo:newRotatation];
- }
- }
- */
- -(NSInteger) calculateDividerIndexBasedOnRotation:(double) testRotation
- {
- double direction = self.mirrored ? 1 : -1;
- testRotation = direction * testRotation;
- if(testRotation<0)
- testRotation=testRotation + 2 * M_PI;
- int activeDividerNumber = testRotation / _rotationStep;
- return activeDividerNumber;
- }
- -(void) updateDividersIfNeeded
- {
- double newRotatation = [[_dividersView.layer.presentationLayer valueForKeyPath:@"transform.rotation.z"] doubleValue];
- //float newRotatation = atan2(_dividersView.transform.b, _dividersView.transform.a);
- //float newRotatation = atan2(_dividersView.transform.b, _dividersView.transform.a);
- double direction = self.mirrored ? 1.0 : -1.0;
- newRotatation = direction * newRotatation;
- newRotatation = roundf(newRotatation * 1000) / 1000;
- if(newRotatation<0)
- newRotatation=newRotatation + 2 * M_PI;
- int activeDividerNumber = (int)((newRotatation / _rotationStep) + 0.5);
- if (activeDividerNumber != _activeDividerIndex)
- {
- if(self.playSound)
- {
- //NSString *clickSoundPath = [[NSBundle mainBundle] pathForResource:@"click_soft_tap" ofType:@"aif"];
- //AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: clickSoundPath], &_clickSoundID);
- NSUserDefaults * def= [NSUserDefaults standardUserDefaults];
- BOOL fxMuted = [def boolForKey:@"fxMuted"];
- if(_changedRotation && !fxMuted)
- AudioServicesPlaySystemSound (_clickSoundID);
- }
- if(_activeDividerIndex>=0 && _activeDividerIndex < _dividersArray.count)
- _dividersArray[_activeDividerIndex].alpha=0.3;
- _activeDividerIndex = activeDividerNumber;
- /*
- for (UIView * divider in _dividersArray)
- {
- divider.alpha=0.3;
- }
- */
- if(activeDividerNumber < _dividersArray.count)
- {
- [_dividersArray[activeDividerNumber] setAlpha:1.0];
- [self.delegate circleViewDidChangeDivider:self];
- }
- }
- }
- #pragma mark - Properties
- -(int) activeDividerIndex
- {
- return _activeDividerIndex;
- }
- -(void) setFillColor:(UIColor *)fillColor
- {
- _fillColor=fillColor;
- [self setNeedsDisplay];
- }
- -(void) setMirrored:(BOOL)mirrored
- {
- _mirrored = mirrored;
- [self setNeedsDisplay];
- }
- -(NSInteger) stopsCount
- {
- return [_dividersArray count];
- }
- -(void) setActiveDivider:(int)dividerIndex
- {
- _activeDividerIndex=dividerIndex;
- double angle = -(dividerIndex) * _rotationStep;
- _dividersView.transform=CGAffineTransformMakeRotation(angle);
- //[_dividersView.layer.presentationLayer setValue:[NSNumber numberWithDouble:angle] forKeyPath:@"transform.rotation.z"];
- [self.delegate circleView:self didRotateTo:angle];
- }
- #pragma mark - Animating color
- - (void)setColorAnimated:(UIColor *)color {
- _sourceColor = self.fillColor; // set start to current color
- _targetColor = color; // destination color
- _startDate = [NSDate date]; // begins currently, you could add some delay if you wish
- _endDate = [_startDate dateByAddingTimeInterval:.3]; // will define animation duration
- [_displayLink invalidate]; // if one already exists
- _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onFrame)]; // create the display link
- [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- }
- - (UIColor *)interpolatedColor:(UIColor *)sourceColor withColor:(UIColor *)targetColor forScale:(CGFloat)scale {
- // this will interpolate between two colors
- CGFloat r1, g1, b1, a1;
- CGFloat r2, g2, b2, a2;
- [sourceColor getRed:&r1 green:&g1 blue:&b1 alpha:&a1];
- [targetColor getRed:&r2 green:&g2 blue:&b2 alpha:&a2];
- // do a linear interpolation on RGBA. You can use other
- return [UIColor colorWithRed:r1+(r2-r1)*scale
- green:g1+(g2-g1)*scale
- blue:b1+(b2-b1)*scale
- alpha:a1+(a2-a1)*scale];
- }
- - (void)onFrame {
- // scale is valid between 0 and 1
- CGFloat scale = [[NSDate date] timeIntervalSinceDate:_startDate] / [_endDate timeIntervalSinceDate:_startDate];
- if(scale < .0f) {
- // this can happen if delay is used
- scale = .0f;
- }
- else if(scale > 1.0f)
- {
- // end animation
- scale = 1.0f;
- [_displayLink invalidate];
- _displayLink = nil;
- }
- [self setFillColor:[self interpolatedColor:_sourceColor withColor:_targetColor forScale:scale]];
- }
- #pragma mark - Draw Rect
- - (void)drawRect:(CGRect)rect
- {
- [self calculateRadiusAndCenter];
- CGRect borderRect = CGRectMake(_center.x-_radius, _center.y - _radius, 2*_radius,2*_radius);
- CGContextRef context = UIGraphicsGetCurrentContext();
- if(_fillColor)
- {
- const CGFloat *components = CGColorGetComponents(_fillColor.CGColor);
- CGContextSetRGBFillColor(context, components[0],components[1],components[2], 1.0);
- }
- else
- {
- }
- CGContextFillEllipseInRect (context, borderRect);
- CGContextFillPath(context);
- }
- #pragma mark - Calculations
- -(void) calculateRadiusAndCenter
- {
- CGPoint pointA;
- CGPoint pointB;
- if(self.mirrored)
- {
- pointA = CGPointMake(0,self.frame.size.height/2);
- pointB = CGPointMake(self.frame.size.width,0);
- }
- else
- {
- pointA = CGPointMake(self.frame.size.width,self.frame.size.height/2);
- pointB = CGPointMake(0,0);
- }
- // getting angle
- CGPoint originPoint = CGPointMake(pointA.x - pointB.x, pointA.y - pointB.y); // get origin point to origin by subtracting end from start
- float bearingRadians = atan2f(originPoint.y, originPoint.x); // get bearing in radians
- //float bearingDegrees = bearingRadians * (180.0 / M_PI); // convert to degrees
- double dx = (pointA.x-pointB.x);
- double dy = (pointA.y-pointB.y);
- double dist = sqrt(dx*dx + dy*dy);
- _radius = fabs(dist / (2 * cos(bearingRadians)));
- if (self.mirrored)
- {
- _center = CGPointMake(_radius, self.frame.size.height/2);
- }
- else
- {
- _center = CGPointMake(self.frame.size.width - _radius, self.frame.size.height/2);
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement