1
UIPanGestureRecognizer를 사용하여 애니메이션을 넘기는 페이지를 구현하려고합니다. 코드는 다음과 같습니다.UIPanGestureRecognizer - CATransform3D를 사용한 translationInView
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self.view];
CGPoint translation = [recognizer translationInView:self.view];
CGPoint velocity = [recognizer velocityInView:self.view];
[recognizer setTranslation:CGPointZero inView:recognizer.view];
switch (recognizer.state) {
case UIGestureRecognizerStateChanged:
{
self.currentTranslation = self.currentTranslation + translation.x;
//only pan left
if (self.currentTranslation > 0.0) {
self.currentTranslation = 0.0;
}
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0/-2000;
self.currentRotation = self.currentTranslation/2 * M_PI/180.0f;
//dont rotate past -90 degrees
if (self.currentRotation <= -M_PI/2) {
self.currentRotation = -M_PI/2+0.0001;
}
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, self.currentRotation, 0.0f, 1.0f, 0.0f);
float ypos = self.view.layer.position.y;
self.view.layer.anchorPoint = CGPointMake(0, 0.5);
self.view.layer.position = CGPointMake(0, ypos);
self.view.layer.transform = rotationAndPerspectiveTransform;
break;
}
default:
break;
}
}
애니메이션이 작동하고 왼쪽으로 드래그하여 페이지가 회전합니다. 그러나 제스처로 꾸준하고 느린 속도로 움직 인 경우에도 페이지는 더 빠르게 회전하기 시작합니다. 플립 보드 (Flipboard) 앱처럼 터치가 움직일 때 페이지가 "선형 적으로"바뀌 길 원합니다. 번역이 어떻게 가속화되지 않도록 제어 할 수 있습니까?
위의 코드에 이미 나와 있습니다. 각도가 커질수록 더 극단적으로 보이는 회전 효과와 관련된 문제라고 생각합니다. 번역 자체가 선형이라고 생각합니다. 나는 단지 회전을 감속시키는 방법을 알아 내야 만합니다. – csoul
@csoul self.currentTranslation이 누적 된 것 같습니다. CATransform3DRotate에서 self.currentTranslation을 추가하는 대신 translation.x를 사용해보십시오. 나는 이것이 문제라고 생각한다. – John