Why I use "pan" after rotae will make view go opposite way?
Asked Answered
P

1

1

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.

enter image description here

Pious answered 29/7, 2012 at 5:44 Comment(0)
D
3

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.

Dealer answered 29/7, 2012 at 7:24 Comment(5)
CGPoint translation=[recongnizer translationInView:self.view]; recongnizer.view.layer.position=CGPointMake(recongnizer.view.layer.position.x+translation.x, recongnizer.view.layer.position.y+translation.y); [recongnizer setTranslation:CGPointMake(0, 0) inView:self.view];Pious
could you check what value your view.layer.anchorPoint has?Dealer
I didn't not set self.view.layer.anchorPoint's value at all,so I think it is 0.Should I use CGContextRolateCTM???Pious
I don't think so, try to set the anchor point to (0.5, 0.5), which will make rotation happens about the view center.Dealer
Still doesn't work,here is my code: CGPoint translation=[recongnizer translationInView:self.view]; self.view.layer.anchorPoint=CGPointMake(0.5, 0.5); recongnizer.view.layer.position=CGPointMake(recongnizer.view.layer.position.x+translation.x, recongnizer.view.layer.position.y+translation.y); [recongnizer setTranslation:CGPointMake(0, 0) inView:self.view]; thxPious

© 2022 - 2024 — McMap. All rights reserved.