2013-08-26 11 views
5

オリエンテーションが変更されたときにサブビューを再レイアウトする必要があるUIViewのサブクラスを作成しています。UIViewサブクラス内でオートローテーションを検出

それはそう、私はむしろ、オートローテーション

を検出するためのUIViewControllerの方法に依存していないと思います余分なコードなし「のどこにプラグイン」できるようにする必要が向きがある場合UIViewのは知っているため、とにかくありかわった?

答えて

9

オリエンテーションの変化を検出するこのような通知はどうですか?

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

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

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
0

私は私のために、これはUIDeviceOrientationDidChangeNotificationより良い働いたことがわかった:

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

私もbeginGeneratingDeviceOrientationNotificationsとの最初の行を追加する必要はありませんでした。

関連する問題