0

私は現在、touchesBeganを機能させるのに苦労しています。

私は現在、このセットアップを持っています

[UIView(UIViewController) -> UIScrollView -> UIView[holderView] -> UILabels[]]

UILabelsこのようにプログラムで追加します

//UIViewController method
UILabel *etiquetaCantidad = [[UILabel alloc] initWithFrame:CGRectMake(350, idx * 35, 50, 30)];
[etiquetaCantidad setTextAlignment:NSTextAlignmentCenter];
[etiquetaCantidad setBackgroundColor:[UIColor azulBase]];
[etiquetaCantidad setTextColor:[UIColor whiteColor]];
[etiquetaCantidad.layer setCornerRadius:5];
[etiquetaCantidad setText:@"0"];
[etiquetaCantidad setUserInteractionEnabled:YES];
[etiquetaCantidad setTag:idx + 100];
[holderView addSubview:etiquetaCantidad];

しかし、私がしようとすると

// UIViewController 
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    NSLog(@"Touch realizado: %@", touches);

}

トリガーされていない、ここで見逃したもの???

4

1 に答える 1

1

さて、私の問題に苦労した後、問題は私と私のUIScrollView間にあることが原因でしたUILabelUIViewController

だから私はUIScrollViewそれがスーパーまたはそれにタッチを渡すためのカテゴリを実装しましたnextResponder

#import "UIScrollView+TouchesBeganPropagable.h"

@implementation UIScrollView (TouchesBeganPropagable)

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    if(!self.dragging){
        [self.nextResponder touchesBegan:touches withEvent:event];
    }else{
        [super touchesBegan:touches withEvent:event];
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    if (!self.dragging){
        [self.nextResponder touchesMoved: touches withEvent:event];
    }
    else{
        [super touchesMoved: touches withEvent: event];
    }
}

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

    if (!self.dragging){
        [self.nextResponder touchesEnded: touches withEvent:event];
    }
    else{
        [super touchesEnded: touches withEvent: event];
    }
}

@end

そうすれば、中間にあるかどうかに関係なくUIViewController、任意の要素と対話する touchesXXXX メソッドを使用できます。UIViewUIScrollView

于 2013-11-08T22:16:24.880 に答える