Ios 以编程方式启动UIgestureRecognitor

Ios 以编程方式启动UIgestureRecognitor,ios,Ios,我想在将UIPangestureRecognitor添加到屏幕截图后立即启动它。由于屏幕截图是通过代码创建的,因此当突出显示某个项目时,用户不会再次按下屏幕。所以如何以编程方式启动识别器 UIView *snapshot = [cell snapshotViewAfterScreenUpdates:NO]; //use the cell to map the snapshot frame to the window because this does a perfect job of

我想在将UIPangestureRecognitor添加到屏幕截图后立即启动它。由于屏幕截图是通过代码创建的,因此当突出显示某个项目时,用户不会再次按下屏幕。所以如何以编程方式启动识别器

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];

您始终可以自己调用该方法

例如,您添加了选择器

- (void) userCellDragged:(UIPanGestureRecognizer)sender;
用于您的平移手势识别器

您可以在视图中的任何位置通过添加

[self userCellDragged:nil];
请记住为此方法添加一个参数,如:

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

通过调用它的目标方法?那么,你的意思是你想触发“UserCellDrawed”方法,并且你试图弄清楚如果它实际上是由手势识别器触发的,如何传递它将接收的参数?正确。通过代码开始这个手势。你可以这样做