Set center point of UIView after CGAffineTransformMakeRotation

I have a UIView that I want the user to be able to navigate around the screen.

-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { CGPoint pt = [[touches anyObject] locationInView:self]; CGPoint center = self.center; CGFloat adjustmentX = pt.x - startLocation.x; CGFloat adjustmentY = pt.y - startLocation.y; center.x += adjustmentX; center.y += adjustmentY; [self setCenter:center]; } 

works fine until I applied the transform to the view as follows:

 self.transform = CGAffineTransformMakeRotation(....); 

However, once the transformation has been applied, drag the results of the UIView into the view moved by the exponential spiral effect.

I assume that I need to make a correction for rotation in the touchhesMoved method, but so far all attempts have not eluded me.

+4
source share
1 answer

You need to translate your transformation into new coordinates, because a transformation other than the identifier is assigned to your view, and moving its center changes the results of the transformation.

Try changing your view center instead.

 self.transform = CGAffineTransformTranslate(self.transform, adjustmentX, adjustmentY); 
+1
source

Source: https://habr.com/ru/post/1333363/


All Articles