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次のようsubviewsに を除外できます。UIButton

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 に答える