IOS:提供更多观看的动态

时间:2012-01-04 10:10:57

标签: ios xcode gesture swipe

我有这段代码:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
[recognizer setNumberOfTouchesRequired:1];
[view1 addGestureRecognizer:recognizer];
[view2 addGestureRecognizer:recognizer];
[view3 addGestureRecognizer:recognizer];
[recognizer release];

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{ //do something}

它只识别在view3中滑动,为什么?我该如何解决这个问题?我应该为每个视图进行新的swipegesture吗?但我有20个观点。

1 个答案:

答案 0 :(得分:2)

如果您有20个视图,它们可能存储在数组或其他内容中?如果是的话,你试过这样的事吗?

 for (unsigned i = 0; i < [yourViewsArray count]; i++){
    UIView *view = [yourViewsArray objectAtIndex:i]; 
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
    [recognizer setNumberOfTouchesRequired:1];
    [view addGestureRecognizer:recognizer];
    [recognizer release];
 }

使用此功能,您可以为每个视图添加新的识别器