如何在半视图上实现滑动手势并在另一半视图上平移手势?

时间:2012-12-28 11:26:21

标签: ios uigesturerecognizer uipangesturerecognizer uiswipegesturerecognizer

如何将平移手势添加到视图的前半部分(0,0,160,480)并在同一视图上添加一个轻扫手势(160,0,160,480)?

视图是表视图,在向左滑动时,单元格内容应该更改,在右侧平移时,tableview应该像facebook ios app一样移动

1 个答案:

答案 0 :(得分:2)

将两个不同的UIview作为带有所需帧大小的mainView的SubView,然后添加所需的手势: -

 UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeVC:)];
    swipeGestureRecognizer.delegate = self;
    [self.subView.view addGestureRecognizer:swipeGestureRecognizer];

    UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panVC:)];
    panGestureRecognizer.delegate = self;
    [panGestureRecognizer requireGestureRecognizerToFail:swipeGestureRecognizer];
    [self.subView2.view addGestureRecognizer:panGestureRecognizer];

当使用gestureRecognizer或otherGestureRecognizer识别手势时,会调用Below方法

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}