Swift - How to detect orientation changes

后端 未结 13 1827
余生分开走
余生分开走 2020-11-29 19:49

I want to add two images to single image view (i.e for landscape one image and for portrait another image)but i don\'t know how to detect orientation changes using swift lan

13条回答
  •  孤独总比滥情好
    2020-11-29 20:52

    Swift 4.2, RxSwift

    If we need to reload collectionView.

    NotificationCenter.default.rx.notification(UIDevice.orientationDidChangeNotification)
        .observeOn(MainScheduler.instance)
        .map { _ in }            
        .bind(to: collectionView.rx.reloadData)
        .disposed(by: bag)
    

    Swift 4, RxSwift

    If we need to reload collectionView.

    NotificationCenter.default.rx.notification(NSNotification.Name.UIDeviceOrientationDidChange)
        .observeOn(MainScheduler.instance)
        .map { _ in }            
        .bind(to: collectionView.rx.reloadData)
        .disposed(by: bag)
    

提交回复
热议问题