0

uiscrollview と、uiscrollview に複数のサブビューがある場合。ユーザーがどこに触れたか、つまり特定のビューまたはスクロールビュー(空白)を知る方法

4

2 に答える 2

3

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;scrollView でタッチを検出するには、次の 2 つの可能性があります。

まず、このメソッドを viewController に実装し、この viewController に scrollview を追加します。

次に、次のように UIScrollView から継承されるカスタム クラスを作成することをお勧めします: .h:

@interface CustomScrollView : UIScrollView 

@end

.m:

#import "CustomScrollView.h"


@implementation CustomScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.nextResponder touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if(!self.dragging){
        [self.nextResponder touchesMoved:touches withEvent:event];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.nextResponder touchesEnded:touches withEvent:event];
}

@end

あなたのVCメイクで:

...

CustomScrollView* customScrollView = [[CustomScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

...

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        NSLog(@"View touched: %@", touch.view);
}
于 2013-10-22T09:50:34.740 に答える