0

当用户触摸其中的 UIImageView 时,我有一个弹出框应该消失。然后我创建另一个 UIImageView,用户将其拖到原始 ViewController 中。我很确定这与第一响应者有关。如何使 touchesBegan、touchesMoved 和 touchesEnded 都直接调用到原始 ViewController?

这是我到目前为止所拥有的:

初始化弹出框:

PopoverCreateNewBoardViewController *content = [PopoverCreateNewBoardViewController new];
    content.delegate = self;
    showPiecesPopover = [[UIPopoverController alloc] initWithContentViewController:content];
    showPiecesPopover.popoverContentSize = CGSizeMake(150.0, 500.0);
    showPiecesPopover.delegate = self;

弹出框.m

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *objectTouched = [touches anyObject];
    if ([objectTouched.view isKindOfClass:[UIImageView class]]) {
        UIImageView *imageViewTouched = (UIImageView*)objectTouched.view;
        [delegate pieceSelectedType:imageViewTouched.tag color:piecesColor];
        [self resignFirstResponder];
        [delegate touchesBegan:touches withEvent:event];
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [delegate touchesMoved:touches withEvent:event];
}

视图控制器.m

-(void)pieceSelectedType:(NSInteger)pieceType color:(NSInteger)pieceColor
{
    selectedPieceImageView.image = [self imageOfPieceType:pieceType color:pieceColor];
    movingPiece = YES;
    [showPiecesPopover dismissPopoverAnimated:YES];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (movingPiece) {
        CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
        [selectedPieceImageView setCenter:touchPoint];
    }
}

使用此代码,在弹出框开始被解除后大约一秒钟后,touchesMoved 停止被调用。

4

0 回答 0