1

UIPanGestureRecognizer を使用してページめくりアニメーションを実装しようとしています。コードは次のとおりです。

- (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 アプリのように、タッチの動きに合わせてページを「直線的に」回転させたい。加速されないように変換を制御するにはどうすればよいですか?

4

1 に答える 1

3

翻訳が蓄積されます。UIGestureRecognizerStateChanged のケースの後にこれをコードに追加します。

    [recognizer setTranslation:CGPointZero inView:self.view];
于 2014-02-28T17:11:38.127 に答える