为什么我使用“平移"旋转后是否会使视线向相反方向移动? [英] Why I use "pan" after rotae will make view go opposite way?

查看:98
本文介绍了为什么我使用“平移"旋转后是否会使视线向相反方向移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么旋转后使用平移"使视图相反?

看来这两个手势都使用了不同的坐标系?旋转使用旋转的一种,而平移使用正常的一种?

如果将视图旋转到0'或360'附近,则平移将是正常的;如果将视图更旋转至180',则平移"将使视图向相反的方向移动.

谢谢.

解决方案

要点是,在您的handRotate方法中,您正在为视图分配旋转变换.这就需要在视图在其父视图中显示的方式发生永久性更改(直到您再次修改变换),并且旋转变换将始终添加"到您对视图的几何属性所做的任何其他更改. >

解释您所看到的行为的是视图位置与其锚点之间的相互作用,如

It seems these two gesture are use diffrent coordinate system? Rotation use the one is rotated,and pan use the normal one?

And if the view is rotated nearby 0' or 360 ',pan will be normal,and if the view is rotated more colse to 180',the "pan" will make view go opposite more.

Thanks.

解决方案

The point is that in your handRotate method you are assigning a rotation transformation to your view. This entails a permanent (until you modify the transformation again) change in the way your view is displayed within its superview, and the rotation transformation will be always "added" to whatever other change you do to the geometrical properties of your view.

What explains the behavior you are seeing is the interplay between the position of your view and its anchor point, as explained in Layer Geometry and Transform. In other words, the center property you are modifying when panning is the result of applying all the transforms that you have defined for your view. On the other hand, what you are trying to do when panning would require modifying the position of the view before the transformation are applied.

A way to go about this is reframing your code by using layers (CALayer) and modifying the layer position property instead of the view center. Like in:

recognizer.view.layer.position = ...

I think that this should fix it.

(You will need to import QuartzCore for that to compile).

Hope this helps.

这篇关于为什么我使用“平移"旋转后是否会使视线向相反方向移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆