Popover为触摸事件重新启动第一响应者以查看调用popover的控制器

时间:2013-05-18 16:38:11

标签: objective-c

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

这是我到目前为止所做的:

初始化Popover:

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

Popover.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];
}

ViewController.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停止被调用。

0 个答案:

没有答案