質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

5316閲覧

[swift]touchesMovedが呼ばれない

SATOU_UKI

総合スコア29

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2017/02/19 06:41

いつもお世話になっております。
UIViewController のサブクラスを作成し、touchイベントを取得できるようにしたつもりだったのですが、
UIViewController の touchesMoved がなぜか1回しか呼ばれない、touchesEnded も呼ばれないといった
現象が起こっていて困っております。どのようにすれば、解決できるでしょうか?

swift3

1class MyUITableView :UITableView{ 2 3 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 4 superview?.touchesBegan(touches, with: event)} 5 6 override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 7 superview?.touchesMoved(touches, with: event)} 8 9 10 override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 11 superview?.touchesEnded(touches, with: event)} 12 13}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

参考①

参考URL: 【Swift】UITableViewのタッチイベントを検知する方法
※ 自分の手元でも呼ばれる時と呼ばれない時があるのでいまいちかもです。

swift

1class ViewController: UIViewController { 2 3 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 4 print("touchesBegan") 5 } 6 7 override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 8 print("touchesMoved") 9 } 10 11 override open func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 12 print("touchesEnded") 13 } 14} 15 16extension UITableView { 17 override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 18 self.next?.touchesBegan(touches, with: event) 19 } 20 21 override open func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 22 self.next?.touchesMoved(touches, with: event) 23 } 24 25 override open func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 26 self.next?.touchesEnded(touches, with: event) 27 } 28}

参考② touchesMovedをどのような理由で取得したいのかわからないのですが、スクロールしているの取りたいのであれば、UIScrollViewDelegateで取得できます。

参考URL: UIScrollViewDelegateの実装とスクロールイベントの通知について(iOS)

swift

1class ViewController: UIViewController { 2 3 func scrollViewDidScroll(_ scrollView: UIScrollView) { 4 print(scrollView.contentOffset) 5 } 6} 7

投稿2017/02/19 07:38

編集2017/02/19 07:40
_Kentarou

総合スコア8490

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

SATOU_UKI

2017/02/19 12:38

_Kentarou様 いつもお世話になっております。 おかげさまで動作させることができました。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問