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.
Asked
Active
Viewed 767 times
2 Answers
0
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.

ArtKorchagin
- 4,801
- 13
- 42
- 58

Paradise
- 558
- 6
- 17
0
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); }

Tunyk Pavel
- 2,473
- 6
- 31
- 46