Disabling user interaction of the current view on screen

前端 未结 7 710
一个人的身影
一个人的身影 2021-01-31 02:52

My app has many views and their respective controllers. Now I have a set of model classes with business logic in them. One of the model classes(subclass of NSObject) has the res

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 03:52

    Maybe you want the whole application to not react at all?

    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    

    use [[UIApplication sharedApplication] endIgnoringInteractionEvents]; to revert this (credits to nerith)

    same for Swift:

    UIApplication.sharedApplication().beginIgnoringInteractionEvents()
    UIApplication.sharedApplication().endIgnoringInteractionEvents()
    

    and Swift 3/4

    UIApplication.shared.beginIgnoringInteractionEvents()
    UIApplication.shared.endIgnoringInteractionEvents()
    

    edit for iOS 13: beginIgnoringInteractionEvents is deprecated in iOS13

    just make a new full size View and lay it over your current view. that will allow you to block any user interaction.

提交回复
热议问题