가장 쉬운 방법은 회전 값을 속성으로 제공하는 UIRotationGestureRecognizer
을 사용하는 것입니다. 당신이 제스처 인식기를 사용할 수없는 경우
(안된)이 같은 시도 :
// Assuming centerPoint is the center point of the object you want to rotate (the rotation axis),
// currentTouchLocation and initialTouchLocation are the coordinates of the points between
// which you want to calculate the angle.
CGPoint centerPoint = ...
CGPoint currentTouchLocation = ...
CGPoint initialTouchLocation = ...
// Convert to polar coordinates with the centerPoint being (0,0)
CGPoint currentTouchLocationNormalized = CGPointMake(currentTouchLocation.x - centerPoint.x, currentTouchLocation.y - centerPoint.y);
CGPoint initialTouchLocationNormalized = CGPointMake(initialTouchLocation.x - centerPoint.x, initialTouchLocation.y - centerPoint.y);
CGFloat angleBetweenInitialTouchAndCenter = atan2(initialTouchLocationNormalized.y, initialTouchLocationNormalized.x);
CGFloat angleBetweenCurrentTouchAndCenter = atan2(currentTouchLocationNormalized.y, currentTouchLocationNormalized.x);
CGFloat rotationAngle = angleBetweenCurrentTouchAndCenter - angleBetweenInitialTouchAndCenter;
참조 위키 백과 또는 극좌표 방법과 직교 및 극 사이의 변환하는 방법에 대한 자세한 내용은 Google 검색을 좌표계.
답변 해 주셔서 감사합니다. 불행히도 제스처는 내가 선호하는 사용자 상호 작용 경험을 제공하지 않습니다. 예를 들어 몸짓으로 너비를 늘리고보기 높이를 고정하는 것은 불가능합니다. 또한 제스처를 사용하면 하나의 손가락으로 오버레이를 움직일 수 없습니다. – adranale
그것은 백만 번 감사했습니다! – adranale