1

たくさんのオブジェクトを持つ UIView がありました。次のような touchesMoved の実装もありました。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"move");
}

最近、ビューをスクロールしたかったので、UIView を開き、Interface Builder でそのオブジェクト クラスを UIScrollView に変更しました。ただし、画面に触れても「touchesMoved」メソッドが呼び出されることはありません。

touchesMoved が再び機能するように助けてもらえますか? 私はそれを壊すために何をしたのかわからない!

編集:このガイドに従ってみましたが、何か間違ったことをした可能性があります。他の投稿を読むと、UIScrollView はタッチ イベント自体を受け入れることができず、レスポンダー チェーンに送信する必要があるようです。この問題を解決するのを手伝ってくれる人には非常に感謝しています... UIScrollView が私のタッチ検出を殺したことに気付いたとき、私のアプリは提出の準備ができていました! (iPhone 4 との互換性を確保するために、アプリの UIView を UIScrollView に変更しました)。

4

1 に答える 1

3

私はちょうどあなたの編集でガイドを見ました、そして私は問題を見ることができると思います. 同様の質問でこの回答を参照してください。

サブクラスUIScrollViewは次のようになります。

#import "AppScrollView.h"

@implementation AppScrollView

- (id)initWithFrame:(CGRect)frame
{
    return [super initWithFrame:frame];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesEnded:withEvent:");

    // If not dragging, send event to next responder
    if (!self.dragging)
        [[self.nextResponder nextResponder] touchesEnded:touches withEvent:event];
    else
        [super touchesEnded: touches withEvent: event];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"AppScrollView touchesMoved:withEvent:");

    [[self.nextResponder nextResponder] touchesMoved:touches withEvent:event];
}

@end

AppScrollViewオブジェクトを含むクラスは、UIScrollViewDelegateプロトコルを採用し、これらのメソッドを実装する必要があります。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"SomeClass touchesMoved:withEvent:");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"SomeClass touchesEnded:withEvent:");
}

ログ出力は次のようになります。

2013-06-11 10:45:21.625 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.625 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.655 Test[54090:c07] AppScrollView touchesEnded:withEvent:
2013-06-11 10:45:21.656 Test[54090:c07] SomeClass touchesEnded:withEvent:
于 2013-06-11T00:46:32.257 に答える