我想在将 UIPanGestureRecognizer 添加到屏幕截图后立即启动它。由于屏幕截图是通过代码创建的,因此当某个项目突出显示时,用户将不会再次按屏幕。那么...如何以编程方式启动识别器?
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;
用于您的平移手势识别器。
您只需添加即可从 View 中的任何位置调用它
[self userCellDragged:nil];
请记住向此方法添加一个参数,例如:
if (sender == nil) {
// Triggered programmatically
}
else {
// proceed as normal
}
关于ios - 以编程方式启动 UIGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22099606/