我想在將其添加到屏幕截圖後立即啓動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];
通過調用其目標方法? – Larme
所以,你說什麼是你想觸發「userCellDragged」方法,你正試圖弄清楚如果它實際上是由手勢識別器觸發它將收到的參數傳遞? – ezekielDFM
正確。通過代碼 –