I'm not sure what you mean by "I am not able to maintain the transform" Anyway, here is a slightly different approach that I think may help you.
For starters, when you apply to a view a transform other than the 'Identity' transform the frame
property becomes meaningless. This means you cannot use its origin
member to change the view's position. You have to use the view's center
property instead.
Also, for dragging, I strongly recommend you use a UIPanGestureRecognizer
instead of the touches...
methods. This is because the gesture recognizer maintains state for you and it's super easy to drag things around.
Here is some example code:
// Create your view and apply all the transforms you want
// --code here--
// Create and assign the UIPanGestureRecognizer
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
[self.currentView addGestureRecognizer:panGesture];
// Here is where the dragging happens
-(void)panDetected:(UIPanGestureRecognizer*)panGesture {
// Get the view that detected the gesture
UIView *view = panGesture.view;
// If dragging started or changed...
if (panGesture.state == UIGestureRecognizerStateBegan || panGesture.state == UIGestureRecognizerStateChanged) {
// Get the translation in superview coordinates
CGPoint translation = [panGesture translationInView:view.superview];
// Get your view's center
CGPoint viewCenter = view.center;
// Add the delta
viewCenter.x += translation.x;
viewCenter.y += translation.y;
view.center = viewCenter;
// Reset delta from the gesture recognizer
[panGesture setTranslation:CGPointZero inView:view.superview];
}
}
I tested this code in a project of mine with a view that has a rotation transform and it works perfectly.
Hope this helps!