Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set a rotation transform that doesn't distort on device rotation?
    primarykey
    data
    text
    <p>I am developing an iPad application that has a set of UIButton instances where I do a slight CGAffineTransform rotation in <code>viewWillAppear:</code> so that they are not perfectly aligned on the screen. A problem occurs, though, when the device is rotated in any direction and the background image of the button becomes more and more skewed the more it is rotated:</p> <p>Correct:</p> <p><img src="https://i.stack.imgur.com/QXCAD.png" alt="enter image description here"></p> <p>After a few device rotations:</p> <p><img src="https://i.stack.imgur.com/uPC6Y.png" alt="enter image description here"></p> <p>Here is the code that I am using to animate the view on <code>viewDidAppear:</code>:</p> <pre><code>/* * Animate video button */ CGPoint videoCenter = self.videoButton.center; self.videoButton.center = CGPointMake(self.videoButton.center.x + 25.0f, self.videoButton.center.y + 25.0f); [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.videoButton.center = videoCenter; self.videoButton.transform = CGAffineTransformRotate(CGAffineTransformIdentity, [self convertDegreesToRadians:4.0f]); } completion:^(BOOL finished) { // Do Nothing }]; </code></pre> <p>I have tried resetting the transform to what I need it to be in <code>willRotateToInterfaceOrientation:</code>, and though it lessens the degree to which it happens, after a number of rotations it produces a similar result.</p> <p>I have tried changing <code>autoresizesSubviews</code> of the main view to be <code>NO</code>:</p> <pre><code>self.view.autoresizesSubviews = NO; </code></pre> <p>But then I have to layout my landscape orientation completely by hand, which I want to avoid.</p> <p><strong>How do I set the rotation transform so that it does not distort the background images of my <code>UIButton</code> on device orientation?</strong></p> <p><strong>UPDATE:</strong></p> <p>I added some log statements in <code>viewWillRotateToInterfaceOrientation:</code> and noticed that the button's width is growing. This explains the image distortion, but why is it even changing? That seems odd to me:</p> <pre> width height ------------------------------- 268.574524 149.81514 286.267822 150 304.092621 150 321.91745 150 339.742279 150 357.567078 150 374.401642 150 391.236206 150 409.061066 150 425.895599 150 442.730164 150 459.564728 150 476.399292 150 493.233826 150 509.078125 150 524.922424 150 540.766663 150 556.611023 150 </pre>
    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.
 

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