내 코드에서 UITouch
을 부드럽게하는 방법이 궁금합니다. 내 UIView
에 UItouch
을 감지 할 수 있지만 CGAffineTransform
을 사용하여보기를 회전하려고하면 원활하게 회전하지 않습니다. 이런 종류의 회전을하려면 iPhone을 길게 누르거나 손가락으로 터치해야합니다. Roambi Visualizer 앱과 같은 부드러운 회전을 어떻게 수행 할 수 있습니까? 도움 주셔서 감사합니다.터치로 UIView의 부드러운 회전
3
A
답변
3
transform
가있는 UIView의 애니메이션 속성입니다, 그래서 당신은 부드럽게 회전하기 위해 코어 애니메이션을 사용할 수 있습니다
CGAffineTransform newTransform = //...construct your desired transform here...
[UIView animateWithDuration:0.2
animations:^{view.transform = newTransform;}];
+0
완벽한 답변을 주셔서 감사합니다! –
1
안녕 내 질문있는 touchesMoved 나를 위해 그 작품에 다음과 같은 해결책을 발견 모든 ... .. 여기
코드가
....UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self.superview];
CGPoint pastLocation = [touch previousLocationInView:self.superview];
currentLocation.x = currentLocation.x - self.center.x;
currentLocation.y = self.center.y - currentLocation.y;
pastLocation.x = pastLocation.x - self.center.x;
pastLocation.y = self.center.y - currentLocation.y;
CGFloat angle = atan2(pastLocation.y, pastLocation.x) - atan2(currentLocation.y, currentLocation.x);
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
// Apply the affine transform
[[self.superview viewWithTag:ROTATE_VIEW_TAG] setTransform:transform] ;
+0
점진적으로 회전 시키려면 [view setTransform : CGAffineTransformRotate (view.transform, angle)]을 사용해야합니다. 그렇지 않으면 위대한 작품! –
1
이 수도 있고 죽은 오래 걸리지 않을 수 있지만, 캠의 대답에 몇 가지 작은 문제가 있습니다.
는 는override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch: UITouch = touches.first as! UITouch
var currentTouch = touch.locationInView(self.view)
var previousTouch = touch.previousLocationInView(self.view)
currentTouch.x = currentTouch.x - self.view.center.x
currentTouch.y = self.view.center.y - currentTouch.y
previousTouch.x = previousTouch.x - self.view.center.x
previousTouch.y = self.view.center.y - previousTouch.y
var angle = atan2(previousTouch.y, previousTouch.x) - atan2(currentTouch.y, currentTouch.x)
UIView.animateWithDuration(0.1, animations: {() -> Void in
bigCircleView?.transform = CGAffineTransformRotate(bigCircleView!.transform, angle)
})
}
UIView의 애니메이션은 매우 부드러운 회전을 할 수 있습니다 : 당신이 빠른에이 일을 찾고 있다면
필요
로, 나는 다음과 같은 알아낼 캠의 답변을 사용 애니메이션으로 시간을 사용하여 원하는대로, – Splendid