Why I use “pan” after rotae will make view go opposite way?

社会主义新天地 提交于 2019-12-11 05:33:20

问题


Why using "pan" after rotate makes view go opposite way?

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.


回答1:


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.



来源:https://stackoverflow.com/questions/11707001/why-i-use-pan-after-rotae-will-make-view-go-opposite-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!