Reputation: 2057
I have added an UIImageView
as a subview in UIView
, and then I move this subview with the following code in UITouchesBegan
.
CGPoint newTouch = [[touches anyObject] locationInView:self];
CGPoint lastTouch = [[touches anyObject] previousLocationInView:self];
float xDif = newTouch.x - lastTouch.x;
float yDif = newTouch.y - lastTouch.y;
translate = CGAffineTransformMakeTranslation(xDif, yDif);
[self setTransform: CGAffineTransformConcat([self transform], translate)];
then I rotate this subview with the following code.
self.transform=CGAffineTransformRotate(self.transform, RADIANS(180));
at this stage, all is well.. but when I try once more to move my Subview, it moves in the opposite direction i.e. when I want to move it upwards it moves downwards.
any ideas? suggestions?
Upvotes: 2
Views: 524
Reputation: 3208
Why are you moving the subview using a translate transform? Just update the center
property. The problem with using a translate transform is that if it is rotated, it will indeed translate in a direction relative to the current rotation (which may not be what you expected, as you have discovered). If you want to insist on using the translate transform (again, why?) then you need to make sure you are rotated back to 0 (neutral), do your translation of position, then rotate back to your desired rotation.
Order of transforms matter.
Upvotes: 2