1

我有 5-10 个不同的按钮UIScrollView

我想UILongPressGestureRecognizer在我的UIScrollView.

-(IBAction)CheckIfUserWantsToDoSomething:(id)sender {
    HoldTimer = [NSTimer scheduledTimerWithTimeInterval:1.2 target:self selector:@selector(DoAction:) userInfo:nil repeats:NO];
}

-(void)DoAction:(id)sender {
    [HoldTimer invalidate];

    //My Code...
}
4

1 回答 1

4

你可以得到所有的UIScrollView's subviews,并像这样过滤掉UIButton's :

for (UIButton *button in myScrollView.superview.subviews) {
    if ([button isKindOfClass[UIButton Class]]) {

    }
}

然后您可以创建并将您的添加UILongPressGestureRecognizer到这些按钮。

UILongPressGestureRecognizer *holdRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(DoAction:)];
[holdRecognizer setMinimumPressDuration:2];

[button addGestureRecognizer:holdRecognizer];
于 2012-06-05T01:42:41.930 回答