2013-08-22 6 views
7
와 함께 작동하도록 jQuery과에 삭제를 받기

나는 UIPanGuestureRecognizer이 코드를 사용하여 전체 뷰에 추가 한 : 나는에 슬쩍을 사용하려면이 코드가 jQuery과이 기본보기 내에서출근 UIPanGestureRecognizer

UIPanGestureRecognizer *pgr = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; 
[[self view] addGestureRecognizer:pgr]; 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"RUNNING2"); 
    return UITableViewCellEditingStyleDelete; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.row >= _firstEditableCell && _firstEditableCell != -1) 
     NSLog(@"RUNNING1"); 
     return YES; 
    else 
     return NO; 
} 

RUNNING1이 로그에 인쇄 및 삭제 버튼이 표시되지 않습니다 : 기능을 삭제합니다. 나는이 이유가 UIPanGestureRecognizer라고 믿지만 확실치 않습니다. 이것이 올바른 경우 어떻게 수정해야합니까? 이것이 올바르지 않으면 원인을 제시하고 수정하십시오. 감사. document에서

+0

당신은 테이블 뷰의 대표로 클래스를 설정 했습니까? – rdelmar

+0

@rdelmar 예. 또한 RUNNING1이 인쇄되지 않을 것이라고 생각하지 않습니다. 하지만 노력해 줘서 고마워. – carloabelli

+2

canEditRorAtIndexPath : 대리자 메서드가 아닌 데이터 소스 메서드이므로 대리자를 설정하지 않은 경우 실행됩니다. – rdelmar

답변

13

:

제스처 인식기는 제스처를 인식하는 경우는, 뷰의 나머지 감각이 취소됩니다.

UIPanGestureRecognizer은 먼저 스 와이프 제스처를 인식하므로 UITableView은 더 이상 접촉을받지 않습니다.

테이블 뷰를 만들려면 제스처 인식기와 동시에 터치를 수신, 제스처 인식기의 위임이 추가 :

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

정확히 내가 무엇을 찾고 있었습니까. 아름답게 작동합니다. 감사! – carloabelli

+0

완벽 ... 훌륭한 작품 ... – davidOhara

0

당신이 사이드 메뉴를 보여주기 위해 예를 들어 UIPanGuestureRecognizer을 사용하는 경우 원하지 않는 부작용이 나타날 수 있습니다 수락 된 답변에서 제안 된대로 모든 경우에 YES를 반환하면됩니다. 예를 들어, 사이드 메뉴를 열 때 테이블 뷰를 위/아래로 스크롤 할 때 (아주 조금 왼쪽/오른쪽 방향으로) 또는 삭제 버튼이 이상하게 작동 할 때 열립니다. 이 부작용을 방지하기 위해 할 수있는 일은 동시 수평 제스처 만 허용하는 것입니다. 이렇게하면 삭제 버튼이 제대로 작동하지만 메뉴를 슬라이드하면 다른 원치 않는 제스처가 차단됩니다.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{ 
    if ([otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) 
    { 
     UIPanGestureRecognizer *panGesture = (UIPanGestureRecognizer *)otherGestureRecognizer; 
     CGPoint velocity = [panGesture velocityInView:panGesture.view]; 
     if (ABS(velocity.x) > ABS(velocity.y)) 
      return YES; 
    } 
    return NO; 
} 

또는 스위프트의

는 :

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { 
    guard let panRecognizer = otherGestureRecognizer as? UIPanGestureRecognizer else { 
     return false 
    } 
    let velocity = panRecognizer.velocity(in: panRecognizer.view) 
    if (abs(velocity.x) > abs(velocity.y)) { 
     return true 
    } 
    return false 
} 
관련 문제