SwiftUIの基本を身につけたい方はこちら

【Xcode/Swift】タップ無効化の警告:’beginIgnoringInteractionEvents()’ was deprecated in iOS 13.0: Use UIView’s userInteractionEnabled property instead

警告内容

‘beginIgnoringInteractionEvents()’ was deprecated in iOS 13.0: Use UIView’s userInteractionEnabled property instead

原因

警告文を見ればその通りなのですが、beginIgnoringInteractionEvents()は、iOS13.0で非推奨になったので、userInteractionEnabledを使ってください。という警告です。

なので、userInteractionEnabledを使いましょう。

解決方法

古い方法
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// タップアクション無効化
UIApplication.shared.beginIgnoringInteractionEvents()
// タップアクション有効か
UIApplication.shared.endReceivingRemoteControlEvents()
// タップアクション無効化 UIApplication.shared.beginIgnoringInteractionEvents() // タップアクション有効か UIApplication.shared.endReceivingRemoteControlEvents()
// タップアクション無効化
UIApplication.shared.beginIgnoringInteractionEvents()

// タップアクション有効か
UIApplication.shared.endReceivingRemoteControlEvents()
新しい方法
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// タップ無効化
view.isUserInteractionEnabled = false
// タップ有効化
view.isUserInteractionEnabled = true
// タップ無効化 view.isUserInteractionEnabled = false // タップ有効化 view.isUserInteractionEnabled = true
// タップ無効化
view.isUserInteractionEnabled = false

// タップ有効化
view.isUserInteractionEnabled = true

評価