I have a UIImageView object that I rotate with frame property and CFAffineTransformMakeRotate and then I want ot move it with moving origin of its frame, but my image moves and reshape strangly.
@implementation TimberView
(void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// Retrieve the touch point
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
[[self superview] bringSubviewToFront:self];
}
(void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
// Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame];
}
The TimberView class is a subclass of UIImageView
Quote from UIView’s frame property reference:
So if you apply some custom transform to your view you cannot use view’s frame property. To move the view change its
centerproperty instead, so your code should be transformed to (not sure if the code is correct or not):If you want just to position view’s center to touched point you can use the following code: