5

向きが変わったときにサブビューを再レイアウトする必要がある UIView のサブクラスを作成しています。

追加のコードなしで「どこにでもプラグイン」できる必要があるため、自動回転を検出するために UIViewController メソッドに依存したくありません

UIView が向きがいつ変更されたかを知る方法はありますか?

4

3 に答える 3

9

向きの変化を検出するために、このような通知はどうですか??

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

ただし、その前に、このような通知を生成するために登録する必要があります。

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
于 2013-08-26T10:26:35.053 に答える
0

私にとって、これはUIDeviceOrientationDidChangeNotificationよりもうまく機能することがわかりました:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("layoutControls"), name: UIApplicationDidChangeStatusBarOrientationNotification, object: nil)

beginGeneratingDeviceOrientationNotifications の最初の行を追加する必要さえありませんでした。

于 2015-11-23T10:44:59.487 に答える