Rxswift: How to observe orientation change with RxSwift

Created on 5 Jul 2016  路  6Comments  路  Source: ReactiveX/RxSwift

Hi,

Is there an Rx property on which we can subscribe for orientation change device ?

Most helpful comment

maybe observe UIDeviceOrientationDidChange notification.

All 6 comments

Hm, I'm not sure whether there are any NSNotification
But you can observe viewWillTransitionToSize kinda like this:

rx_sentMessage(#selector(UIViewController.viewWillTransitionToSize(_:withTransitionCoordinator:)))
         .subscribeNext { (params) in
            //Do something here on size class change
         }
         .addDisposableTo(disposeBag)

Looks a little bit complex. It seems better to

use view.rx_observe(CGRect.self, "frame")

maybe observe UIDeviceOrientationDidChange notification.

NSNotificationCenter.defaultCenter().rx_notification(UIDeviceOrientationDidChangeNotification).subscribeNext {}

Assuming this is resolved :)

The solution is to find a better alternative.

 NotificationCenter.default.rx.notification(UIDevice.orientationDidChangeNotification)
            .observeOn(MainScheduler.instance)
            .subscribe(onNext: { data in
                print("data \(data)")
            })
        .disposed(by: disposeBag)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

RobinFalko picture RobinFalko  路  3Comments

RafaelPlantard picture RafaelPlantard  路  3Comments

jeremiegirault picture jeremiegirault  路  3Comments

apoloa picture apoloa  路  3Comments

acecilia picture acecilia  路  3Comments