Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>For starters, when you apply to a view a transform other than the 'Identity' transform the <code>frame</code> property becomes meaningless. This means you cannot use its <code>origin</code> member to change the view's position. You have to use the view's <code>center</code> property instead. </p> <p>Also, for dragging, I strongly recommend you use a <code>UIPanGestureRecognizer</code> instead of the <code>touches...</code> methods. This is because the gesture recognizer maintains state for you and it's super easy to drag things around.</p> <p>Here is some example code:</p> <pre><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]; } } </code></pre> <p>I tested this code in a project of mine with a view that has a rotation transform and it works perfectly.</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload