Я использовал ниже функцию для 3dRotation на виде. Но я не хочу tilt/flip на вид, я просто хочу левый/правый/вверх/вниз движение на вид.Как избежать наклона/поворота на поворот CATransform3D в iOS?
Как я избегаю наклона и флип вращение на моем взгляде?
- (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];
}
}
Это в Swift, но должно помочь понять, как вращать, перемещать и масштабировать слои в 2d: http://stackoverflow.com/a/34438890/1694526 – sketchyTech