7

I am about driven to despair trying to achieve something so simple.

I have a view with a menu that, using touchEvents slides from the left when it is gestured to do so with a horizontal swipe. I don't use gesture recognisers, I simply use the touchesBegan, touchesMoved, etc.. and track the x coordinate difference between the starting touch position, those in-between and the finishing touch position. It works great.

But, when in the body I have a UITableView, the touch events no longer find their way up the hierarchy to the view managing the menu. I tried to get around this by passing touches to superview/nextResponder, which sort of works, but I see a touchesBegan and 2 touchesMoved calls before it simply stops being processed further up the hierarchy.

Specifically, I have a SlideMenuView, in which there is a menu view and a body view. Inside the body view, I have at some point the UITableView. I see (via NSLog) that the touches* methods are called from start to finish just fine. I pass them on to nextResponder and begin to see them in SlideMenuView also - but after 2 calls to touchesMoved, they seem to stop in SlideMenuView but continue in my UITableView.

I am overriding the UITableView to do this, but I have changed nothing more inside of it.

I know that this must be possible, as it is in the Facebook app. You can swipe anywhere in the body, which is scrollable, horizontally and reveal the menu. I want the same thing to naturally occur here, but it appears as though something weird is happening, and the UITableView is consuming or destroying the events.

Can anybody help me out with this? Somebody must have achieved this in a clean way.

4

1 に答える 1

9

さて、興味のある人は誰でも-私はきれいな解決策を見つけました。

Apple は自分たちが何をしているかを知っています。昔はオーバーライドしてtouchesBeganいましたが、その後 が導入されましGestureRecognizersた。UIScrollView(および などのサブクラス) などの一部のコントロールではUITableView、イベント レスポンダー システムを解体しているように見えます。Gesture Recognizers特別なことは何もせず、単にこれらの , ... メソッドにフックすると仮定したことで、私は過ちを犯しましたtouchesBegan- これは正しくありません。

最も安全な方法は、 を使用することGesture Recognizersです。具体的には、すべての違いを生むことができるいくつかのオプションがあります。私の場合のよう.cancelsTouchesInView = YESに。

だから私がしたことはPanGestureRecognizer、メニュービューで a を使用し、 に設定.cancelsTouchesInViewするYESと機能します。私はtouchesBegan疫病のように ... を避け、複雑なもののためにカスタムジェスチャレコグナイザーを作成します。

これが私のように誰かが髪を引っ張るのに役立つことを願っています!

于 2012-10-05T10:22:33.667 に答える