如何在 objective c 中将标签移动到矩形后从标签中删除触摸操作

how to remove touch action from label after moving it to a rectangle in objective c

我在标签上应用了触摸移动操作,将其拖动到一个矩形框内,它可以通过触摸很好地移动,现在我想在标签被放入矩形时从标签中删除触摸操作,我该如何获得帮助。 这是我在标签拖动结束后的代码。

- (void)dragEnd:(UIPanGestureRecognizer *)gestureRecognizer {
BOOL cancelPanGesture = YES;
if (cancelPanGesture) {
             gestureRecognizer.enabled = NO;
}
if(rectangle.frame.size.width ==  _lbl.frame.size.width){
    gestureRecognizer.enabled = NO;
}
if (gestureRecognizer.state == UIGestureRecognizerStateCancelled) {
    gestureRecognizer.enabled = YES;
}

试试这个

if(rectangle.frame.size.width ==  _lbl.frame.size.width){
    gestureRecognizer.enabled = NO;
    _lbl.userInteractionEnabled = false;
    UILabel *tapLable = (UILabel *)[gestureRecognizer view]; 
    [tempLabel removeGestureRecognizer:gestureRecognizer];
}

希望这对您有所帮助:)

if(CGRectContainsRect(rectangle.frame, _lbl.frame){
    gestureRecognizer.enabled = NO;
    _lbl.userInteractionEnabled = false;
    UILabel *tapLable = (UILabel *)[gestureRecognizer view]; 
    [tempLabel removeGestureRecognizer:removeGestureRecognizer];
}