Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should I interact with the geometry of a UIView, disregarding any transforms applied?
    primarykey
    data
    text
    <p>I have a view that I would like the user to rotate around its center, by tapping and holding somewhere and just move their finger round and round.</p> <p>I have all the geometry worked out; What I do is store the initial touch angle relative to the center as offsetAngle, then my touchesMoved method looks like this:</p> <pre><code>- (void) touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event { self.transform = CGAffineTransformMakeRotation(0); CGPoint location = [[touches anyObject] locationInView: self]; CGPoint actualCenter = [self convertPoint: self.center fromView: self.superview]; CGPoint relativeTouch = [MathHelper translatePoint:location relativeTo: actualCenter]; CGPoint zero = CGPointMake(0, 0); float angle = [MathHelper getAngleForPoint:zero andPoint:relativeTouch]; self.transform = CGAffineTransformMakeRotation(offsetAngle-angle); } </code></pre> <p>The ugly bit is the first line, where I have to restore the rotation in order to get the correct event positions in the view. If I don't that, then the locations jump all over the place as there's no continuity, since the view is rotating...</p> <p>Another issue is when you want to manipulate a view's frame (eg. moving it down), when the view has a transform applied:</p> <pre><code>- (IBAction)toggleSettingsView { BOOL state = [settingsSwitch isOn]; float height = optionsView.bounds.size.height; CGRect polygonFrame = polygonView.frame; [UIView beginAnimations:@"advancedAnimations" context:nil]; [UIView setAnimationDuration:0.3]; if (state) { optionsView.alpha = 1.0; polygonFrame.origin.y += height; } else { optionsView.alpha = 0.0; polygonFrame.origin.y -= height; } polygonView.frame = polygonFrame; [UIView commitAnimations]; } </code></pre> <p>This distorts the view heavily.</p> <p>I must mention that both the CGTransform and the CALayer transform have the same effect.</p> <p>This smells like I'm doing something wrong, but I don't know what I should be doing.</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. 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