I'm noob in ios development. I need some help. I have custom UIButton with picture "arrow", so I need to rotate this button by pressing and moving finger in +360 gr. and -360 gr., like compass arrow.
How to Rotate UIButton by tap and hold (hold - rotate by finger)
810 Views Asked by Tunyk Pavel At
2
There are 2 best solutions below
0
On
In detail, you can custom a rotateView,then:
1: In the delegate method of "touchesBegan", get initialPoint of finger and initialAngle.
2: During "touchesMoved",get the newPoint of finger:
CGPoint newPoint = [[touches anyObject] locationInView:self];
[self pushTouchPoint:thePoint date:[NSDate date]];
double angleDif = [self angleForPoint:newPoint] - [self angleForPoint:initialPoint];
self.angle = initialAngle + angleDif;
[[imageView layer] setTransform:CATransform3DMakeRotation(angle, 0, 0, 1)];
3: At last, in "touchesEnded" you can calculate final AngularVelocity.
If anything being confused, for more detail, you can write back.
Here is code that makes rotation.
-(void)LongPress:(UILongPressGestureRecognizer *)gesture { CGPoint p = [gesture locationInView:self.view]; CGPoint zero; zero.x = self.view.bounds.size.width / 2.0; zero.y = self.view.bounds.size.height / 2.0; CGPoint newPoint; newPoint.x = p.x - zero.x; newPoint.y = zero.y - p.y; CGFloat angle; angle = atan2(newPoint.x, newPoint.y); self.myButton.transform = CGAffineTransformRotate(CGAffineTransformIdentity, angle); }