Monday, February 5, 2018

Change UIBezierArc colour, when its handle is drawn inside or outside from handle only

Leave a Comment

I have a circular slider, which has a bezier arc drawn in it, an arc has two handles at start and end point in slider, arc is drawn in circular slider.

I am able to draw bezier curve along the circular slider with the help of start and end handles.

I want to change the colour of arc when it is dragged 45 inside or 45 outside from handle only and it should not change arc colour when it is dragged in the circular slider.

1- if 45 towards inside - change redColor

2- if dragged inside between 45 to 90 - change Green Color

3- if 45 towards outside - change blueColor

4- if dragged outside between 45 to 90 change to Green Color

Note- while dragging inside and outside it should not change other slider arc's color.

enter image description here

The color should only change, when it is dragged inside and outside only not when it is dragged in circle.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; _dragging = YES;  if (!self.isDragging) {     return; }  if ([self.delegate respondsToSelector:@selector(sliderDraggin:)]) {     [self.delegate sliderDraggin:self]; }  UITouch *touch = [touches anyObject]; //UITouch *touch = [touches anyObject];  NSUInteger nearestHandleIndex = [self indexOfNearesPointForTouch:touch]; _nearesHandle = (nearestHandleIndex != NSNotFound) ? _handles[@(nearestHandleIndex)] : nil;   CGPoint location = [touch locationInView:self]; CGFloat distance = [_math distanceBetweenPoint:_centerPoint andPoint:location];    CGFloat inOff = _radius - _sliderWidth - _offset.inside; CGFloat outOff = _radius + _offset.outside;  if (distance < inOff || distance > outOff) {     if (self.isNeedToRevoke)     {         _dragging = NO;         return;     } }  dispatch_async(dispatch_get_main_queue(), ^{     int a = AngleFromNorth(_centerPoint, location, EVA_FLIPPED);     [self moveView:_nearesHandle toAngle:a];      [self drawArc]; });  [self informDelegateAboutHandles]; } 

1 Answers

Answers 1

You've calculated the distance.

  1. So, first, don't exit if it's less than < inOff or > outOff.

  2. Instead, set the color based upon distance, perhaps:

    UIColor *arcColor;  if (distance < (inOff - 45)) {      arcColor = [UIColor redColor]; } else if (distance > (outOff + 45)) {      arcColor = [UIColor redColor]; } else {      arcColor = [UIColor greenColor]; } 

    Clearly, tweak the logic as you see fit, but that's likely to be the basic idea.

  3. Use this arcColor to update whatever color-specific property is used by your drawing routine.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment