rotate UI subview (CFAffline Transform)

2014-07-18 Thread 2551
I have a problem which I can't find anyone else asking after hours of searches 
through stackexchange and the like. 

In a UIView, I'm rotating a subview with a Gesture recognizer that calls this 
selector:

- (IBAction)rotateShape:(UIRotationGestureRecognizer *)gesture {
gesture.view.transform = CGAffineTransformMakeRotation(gesture.rotation);
}

The rotation performs as expected and all is right with the world. However, as 
soon as I attempt to touch or move the rotated subview again (it also has a pan 
gesture), it reverts to its original orientation. 

It seems the original transform values are still being retained and held by the 
object or by the drawing context (I'm still not quite comfortable with all the 
graphics theory; indeed, this is my first attempt at trying to unlock its 
mysteries). What else do I need to do to ensure the new rotated, orientation 
sticks so that I can move the shape without it reverting to the original 
orientation?

Thanks for any help.


Phil


signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: rotate UI subview (CFAffline Transform)

2014-07-18 Thread Cody Garvin
Transforms are meant to be tiered / layered. In other words, if you do another 
transform via a pan or rotation, it’s going to reset. If your view was already 
scaled (matrix has been edited), doing a Make transform (ex: 
CGAffineTransformMakeRotation) would reset it. Transforms manipulate the 
layer(s). Your view isn’t aware the layer has been tampered with.

If it isn’t another transform that is resetting the layer, then you need to 
reapply your transform. You can can easily get your current transformation via:

CGAffineTransform transformation = theRotatedView.transform;
CGFloat amountRotated = atan2f(transformation.b, transformation.a); // b and a 
are the values manipulated for matrix math. 

A debugging method that you can use is: NSStringFromCGAffineTransform(), will 
help output your current transform. I’m sure you’ll see the matrix numbers 
reset.

Regards

- Cody

It would help to see the code that makes the pan gesture. 
 On Jul 18, 2014, at 4:51 AM, 2551 2551p...@gmail.com wrote:
 
 I have a problem which I can't find anyone else asking after hours of 
 searches through stackexchange and the like. 
 
 In a UIView, I'm rotating a subview with a Gesture recognizer that calls this 
 selector:
 
 - (IBAction)rotateShape:(UIRotationGestureRecognizer *)gesture {
gesture.view.transform = CGAffineTransformMakeRotation(gesture.rotation);
 }
 
 The rotation performs as expected and all is right with the world. However, 
 as soon as I attempt to touch or move the rotated subview again (it also has 
 a pan gesture), it reverts to its original orientation. 
 
 It seems the original transform values are still being retained and held by 
 the object or by the drawing context (I'm still not quite comfortable with 
 all the graphics theory; indeed, this is my first attempt at trying to unlock 
 its mysteries). What else do I need to do to ensure the new rotated, 
 orientation sticks so that I can move the shape without it reverting to the 
 original orientation?
 
 Thanks for any help.
 
 
 Phil
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/cody%40servalsoft.com
 
 This email sent to c...@servalsoft.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: rotate UI subview (CFAffline Transform)

2014-07-18 Thread Steve Christensen
On Jul 18, 2014, at 4:51 AM, 2551 2551p...@gmail.com wrote:

 I have a problem which I can't find anyone else asking after hours of 
 searches through stackexchange and the like. 
 
 In a UIView, I'm rotating a subview with a Gesture recognizer that calls this 
 selector:
 
 - (IBAction)rotateShape:(UIRotationGestureRecognizer *)gesture {
gesture.view.transform = CGAffineTransformMakeRotation(gesture.rotation);
 }
 
 The rotation performs as expected and all is right with the world. However, 
 as soon as I attempt to touch or move the rotated subview again (it also has 
 a pan gesture), it reverts to its original orientation.

No, when you apply a transform to a view, it becomes _the_ transform; it isn't 
retaining previous translation state. Based on what you've said, it sounds like 
when you touch/move the object that you're applying a translation transform to 
the view.

 It seems the original transform values are still being retained and held by 
 the object or by the drawing context (I'm still not quite comfortable with 
 all the graphics theory; indeed, this is my first attempt at trying to unlock 
 its mysteries).

You may already know this but the CFAffineTransformMake*() functions apply a 
single operation (rotate, scale or translate) to the identity transform. If, 
for example, you called CGAffineTransformMakeRotation() and then later 
CGAffineTransformMakeTranslation(), then the rotation will be lost.

 What else do I need to do to ensure the new rotated, orientation sticks so 
 that I can move the shape without it reverting to the original orientation?

Keep track of translation and rotation values in your model and then build 
translated+rotated transforms that reflect the current state of each object.

- (IBAction)rotateShape:(UIRotationGestureRecognizer *)gesture {
   modelObject = ...;

   modelObject.rotation = gesture.rotation;
   gesture.view.transform = [self transformForModelObject:modelObject];
}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

[Solved] rotate UI subview (CFAffline Transform)

2014-07-18 Thread 2551
Thanks Steve and Cody

You were both correct that what was happening was that the subsequent 
translation was cancelling the rotation. All I needed to do was store the 
rotation as a CGFloat on the object and then call the rotation again after the 
move. 

Thanks again.





signature.asc
Description: Message signed with OpenPGP using GPGMail
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com