2014-02-28 6 views
2

UIPanGestureRecognizer를 스크린 샷에 추가 한 직후에 시작하고 싶습니다. 스크린 샷은 코드를 통해 만들어 지므로 항목이 강조 표시되면 사용자가 화면을 다시 누르지 않습니다. 그럼 ... 어떻게 인식기를 프로그래밍 방식으로 시작합니까?프로그래밍 방식으로 UIGestureRecognizer 시작

UIView *snapshot = [cell snapshotViewAfterScreenUpdates:NO]; 

    //use the cell to map the snapshot frame to the window because this does a perfect job of accounting for table offset, etc. Other methods put the view a little to the side or way off 
    CGRect newFrame = snapshot.frame; 
    newFrame.origin = [cell convertPoint:newFrame.origin toView:self.view.window]; 
    [snapshot setFrame:newFrame]; 

    [HelperMethods shadowForView:cell color:[UIColor blackColor] offset:CGSizeMake(1, 1) opacity:.7 radius:snapshot.frame.size.width/4]; 

    //[self.view addSubview:snapshot]; 
    newFrame.origin.y -=10; 

    //move the frame a little to let user know it can be moved 
    [UIView animateWithDuration:.2 animations:^{ 
     [snapshot setFrame:newFrame]; 
    }]; 

    //add a long press that kills the tap if recognized 
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(userCellDragged:)]; 
    [pan setMinimumNumberOfTouches:1]; 
    [pan setMaximumNumberOfTouches:1]; 

    [cell addGestureRecognizer:pan]; 
+1

:

당신 같은이 방법 뭔가에 매개 변수를 추가해야합니다 단순히

[self userCellDragged:nil]; 

을 추가하여보기에서 어디에서나 부를 수있는? – Larme

+0

그렇다면 "userCellDragged"메서드를 트리거하고 실제로 제스처 인식기에 의해 트리거 된 경우받을 인수를 전달하는 방법을 파악하려고합니다. – ezekielDFM

+0

수정. [UILongPressGesture를 프로그래밍 방식으로 어떻게 전송할 수 있습니까?] –

답변

2

누릅니다.

예를 들어, 당신은 당신의 팬 제스처 인식기를 위해 선택

- (void) userCellDragged:(UIPanGestureRecognizer)sender; 

을 추가했습니다. 목표 메소드를 호출하여

if (sender == nil) { 
    // Triggered programmatically 
} 
else { 
    // proceed as normal 
} 
0

가없이 작동을보다 효율적으로 사용할 UIGestureRecognizer 수 있음 "시작"당신은 항상 자신의 메소드를 호출 할 수

관련 문제