0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

タップやスワイプの処理をさせない様にする(isUserInteractionEnabled)

Posted at

今回の内容

  • .isUserInteractionEnabledでタップや長押しやスワイプ時の処理をさせない。

コードと簡単解説

  • これだけでviewに対するタップ、長押し、スワイプ時の処理を働かせることができなくなります。
    view.isUserInteractionEnabled = false

使ってみる

  • viewを5回タップしたら@objc func screenTap(){}の処理が働かなくなります。
import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var detectionResultLabel: UILabel!

    var tapCount = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        let tapDetection = UITapGestureRecognizer(target: self, action: #selector(screenTap))
        view.addGestureRecognizer(tapDetection)
    }

    @objc func screenTap(){
        
        if tapCount == 5{
            
            self.view.isUserInteractionEnabled = false
            
        }else{           
     
            tapCount += 1
            detectionResultLabel.text = "\(tapCount)回、画面をタップしました"     
        }   
    }

}

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?