1

UIScrollViewの上にUIViewがあります。

UIViewをキャッチしながら、ScrollViewを通常どおりスクロールできるようにしたいと思います。

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

唯一の問題は、両方のサブビューで同時にタッチを検出できないように見えることです。一番上のものuserInteractionEnabledをNOに設定できます。しかし、それは両方を手に入れるのに本当に役立ちません。

何かご意見は??

ありがとう!

4

1 に答える 1

-1

私のプロジェクトの 1 つで、1 つのビューでタッチをキャッチし、この方法で 2 番目のビューにメソッドを渡します。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];

    // Do something here

    [otherView touchesEnded:touches withEvent:event];
} 

編集:タッチを管理するためだけに 3 番目の UIView を使用することもできます。

ビューの上に 3 番目の UIView を配置し (画面と同じ幅にする必要があります)、タッチを管理します。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];

    // Get touch position
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:self.view];

    // Use location to pass touches to one view ot the other

    if (location == something) {
        [oneView touchesEnded:touches withEvent:event];
    } else {
        [otherView touchesEnded:touches withEvent:event];
    }
}
于 2013-08-17T23:03:48.123 に答える