私のアプリでは、デバイスの回転後に画像を中央に保ちたいと思っています。このために、willRotateToInterfaceOrientation メソッドと didRotateFromInterfaceOrientation メソッドを使用して、平行移動ベクトルを決定しています。私は次のコードを使用しています:
-(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 ...
}
NSLog が self.view の存在を示しているため、self.view.bounds または self.view.frame メンバーにアクセスできない理由が本当にわかりません。次の出力が生成されます。
-[MapViewController willRotateToInterfaceOrientation:duration:] ...
self.view=<UIView: 0x685fcc0; frame = (0 0; 320 367); autoresize = RM+BM; layer = <CALayer: 0x685fcf0>>
self.view.bounds=(null)
self.view.frame=(null)
self.view.frame=(null)
-[MapViewController didRotateFromInterfaceOrientation:] ...
self.view=<UIView: 0x685fcc0; frame = (0 0; 480 219); autoresize = RM+BM; layer = <CALayer: 0x685fcf0>>
self.view.bounds=(null)
self.view.frame=(null)
self.view.frame=(null)
これは本当に私を狂わせるからです。アドバイス、コメント、またはヘルプは非常に高く評価されています。事前に感謝します!