響應觸摸事件的方法

如果想讓一個視圖對觸摸事件做出響應, 就需要實現能夠響應觸摸事件的方法

總共有四個能夠響應觸摸事件的方法

  • - (void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event;

    當剛開始觸摸的時候觸發(手指剛接觸到視圖)

  • - (void)touchesMoved:(NSSet )touches withEvent:(UIEvent )event;

    當手指在視圖內移動時觸發(前提是手指沒有離開屏幕)

  • - (void)touchesEnded:(NSSet )touches withEvent:(UIEvent )event;

    當觸發結束的時候觸發(此時手指已經離開了屏幕)

  • - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

    當觸摸取消時觸發(觸發意外中斷, 比如有電話進來)

    如果需要用多點觸摸, 需要在初始化方法中設置開啓多點觸摸, 設置方法如下:


    self.multipleTouchEnabled = YES;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章