Note that there are some explanatory texts on larger screens.

plurals
  1. POaccess self.view.bounds in willRotateToInterfaceOrientation
    text
    copied!<p>In my app I want to keep an image centered after a device rotation. For this I'm using the willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation methods to determine a translation-vector. I'm using the following code:</p> <pre><code>-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { NSLog(@"%s ...", __func__); NSLog(@"\t self.view=%@", self.view); NSLog(@"\t self.view.bounds=%@", self.view.bounds); NSLog(@"\t self.view.frame=%@", self.view.frame); NSLog(@"\t self.view.frame=%@", [[self view] frame]); // Save previous bounds to determine translation after rotation occurred. _previousViewBounds = self.view.bounds; } -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { NSLog(@"%s ...", __func__); NSLog(@"\t self.view=%@", self.view); NSLog(@"\t self.view.bounds=%@", self.view.bounds); NSLog(@"\t self.view.frame=%@", self.view.frame); NSLog(@"\t self.view.frame=%@", [[self view] frame]); // Restore previous view.bounds and use new view.bounds to calculate translation. CGFloat tx = self.view.bounds.origin.x - _previousViewBounds.origin.x; CGFloat ty = self.view.bounds.origin.y - _previousViewBounds.origin.y; // ... do translation stuff ... } </code></pre> <p>I really don't understand why I can't access the self.view.bounds or self.view.frame members because my NSLog show the self.view exists. The following output is generated:</p> <pre><code>-[MapViewController willRotateToInterfaceOrientation:duration:] ... self.view=&lt;UIView: 0x685fcc0; frame = (0 0; 320 367); autoresize = RM+BM; layer = &lt;CALayer: 0x685fcf0&gt;&gt; self.view.bounds=(null) self.view.frame=(null) self.view.frame=(null) -[MapViewController didRotateFromInterfaceOrientation:] ... self.view=&lt;UIView: 0x685fcc0; frame = (0 0; 480 219); autoresize = RM+BM; layer = &lt;CALayer: 0x685fcf0&gt;&gt; self.view.bounds=(null) self.view.frame=(null) self.view.frame=(null) </code></pre> <p>Anybody ideas in what's going wrong or I'm missing, because this is really driving me nuts. Any advice, comments or help very much appreciated, thanks in advance!</p>
 

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