2016-12-09 6 views
2

以下の関数を3dRotationのビューで使用しました。しかし、私はチルト/フリップを表示することを望んでいない、私はちょうど左/右/上/下に移動するにはの動きを見てほしい。iOSのCATransform3Dローテーションで傾斜/フリップを避ける方法は?

どのように避けてくださいチルトと反転私のビューにローテーション?

- (void)Move3dPan:(UIPanGestureRecognizer *)gesture 
{ 
    if (gesture.state == UIGestureRecognizerStateChanged) 
    { 
     CGPoint displacement = [gesture translationInView:self.view]; 
     CATransform3D currentTransform = self.popUpView.layer.sublayerTransform; 

     if (displacement.x==0 && displacement.y==0) 
     { 
      // no rotation, nothing to do 
      return; 
     } 

     CGFloat totalRotation = sqrt(displacement.x * displacement.x + displacement.y * displacement.y) * M_PI/360.0; 
     CGFloat xRotationFactor = displacement.x/totalRotation; 
     CGFloat yRotationFactor = displacement.y/totalRotation; 

     CATransform3D rotationalTransform = CATransform3DRotate(currentTransform, totalRotation, 
                  (xRotationFactor * currentTransform.m12 - yRotationFactor * currentTransform.m11), 
                  (xRotationFactor * currentTransform.m22 - yRotationFactor * currentTransform.m21), 
                  (xRotationFactor * currentTransform.m32 - yRotationFactor * currentTransform.m31)); 

     [CATransaction setAnimationDuration:0]; 

     self.popUpView.layer.sublayerTransform = rotationalTransform; 

     [gesture setTranslation:CGPointZero inView:self.view]; 
    } 
} 
+0

を働くことを願っています:http://stackoverflow.com/a/34438890/1694526 – sketchyTech

答えて

1
-(void) startAnimatingCupView 

{ 

    [self stopAnimatingCupView]; 

    timer = [NSTimer scheduledTimerWithTimeInterval:0.8 repeats:true block:^(NSTimer * _Nonnull timer) { 

     [self animateCupView]; 

    }]; 

} 


-(void) animateCupView{ 

    [UIView animateWithDuration:0.4 animations:^{ 

     self.imgCup.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(180)); 

    } completion:^(BOOL finished) { 

     [UIView animateWithDuration:0.4 animations:^{ 

      self.imgCup.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(360)); 

     }]; 

    }]; 

} 


-(void) stopAnimatingCupView{ 

    if (timer != nil) { 

     [timer invalidate]; 

     timer = nil; 

    } 

    [self.imgCup.layer setTransform:CATransform3DIdentity]; 

} 

私は、これはこれはスウィフトであるが、2dに、移動やスケール層を回転させる方法を理解するのに役立つはずです

+0

あなたの答えをありがとう。 私はUIPanGestureRecognizerを使ってタッチ移動で3drotationを望みます。 –

関連する問題