本文介绍了我想要一个“绘图弹出窗口",通过单击tableviewcell出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在tableviewcell中单击时,我希望有一个带有签名"drawing"的弹出窗口.喜欢这张照片:

I would like to have a popover with a signature "drawing" when I click in a tableviewcell.Like this picture :

这是我的代码:

- (void)didSelectWithTableView:(UITableView *)tableView controller:(UIViewController *)controller
{
    red = 0.0/255.0;
    green = 0.0/255.0;
    blue = 0.0/255.0;
    brush = 2.0;
    opacity = 1.0;

    viewController = [[UIViewController alloc] init];

    mainImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, viewController.view.frame.size.width, viewController.view.frame.size.height)];
    mainImage.backgroundColor = [UIColor whiteColor];
    tempDrawImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, viewController.view.frame.size.width, viewController.view.frame.size.height)];
    tempDrawImage.backgroundColor = [UIColor whiteColor];
    [viewController.view addSubview:mainImage];
    [mainImage setContentMode:UIViewContentModeScaleToFill];
    [viewController.view addSubview:tempDrawImage];
    [tempDrawImage setContentMode:UIViewContentModeScaleToFill];

    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn addTarget:self
                action:@selector(save)
      forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitle:@"Save" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    NSLog(@"frame : %@", viewController.view);
    saveBtn.frame = CGRectMake(viewController.view.frame.origin.x + 570, viewController.view.frame.origin.y + 20, 60.0, 80.0);
    [viewController.view addSubview:saveBtn];

    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelBtn addTarget:self
                  action:@selector(reset)
        forControlEvents:UIControlEventTouchUpInside];
    [cancelBtn setTitle:@"Reset" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    NSLog(@"frame : %@", viewController.view);
    cancelBtn.frame = CGRectMake(viewController.view.frame.origin.x + 20, viewController.view.frame.origin.y + 20, 60.0, 80.0);
    [viewController.view addSubview:cancelBtn];

    SignaturePopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
    SignaturePopover.delegate = self;
    SignaturePopover.popoverContentSize = CGSizeMake(644, 425); //your custom size.

    [SignaturePopover presentPopoverFromRect:self.contentView.frame inView:self.contentView permittedArrowDirections: UIPopoverArrowDirectionDown | UIPopoverArrowDirectionUp animated:YES];  
}

问题是,当我单击tableviewcell时,该函数在TableViewCell中被很好地调用,但是当我在弹出窗口中单击时它们未被调用:

The problem is that when I click on the tableviewcell, this functions are well called in the TableViewCell, but they are not called when I click in the popover :

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];

    [self.nextResponder touchesBegan:touches withEvent:event];
    NSLog(@"viewController : %@", self.class);
    if (![self.class isSubclassOfClass: [FXFormSignatureCell class]])
    {
        mouseSwiped = NO;
        UITouch *touch = [touches anyObject];
        lastPoint = [touch locationInView:viewController.view];
    }
}

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

    [self.nextResponder touchesMoved:touches withEvent:event];
        mouseSwiped = YES;
        UITouch *touch = [touches anyObject];
        CGPoint currentPoint = [touch locationInView:viewController.view];

        UIGraphicsBeginImageContext(viewController.view.frame.size);
        [self.tempDrawImage.image drawInRect:CGRectMake(0, 0, viewController.view.frame.size.width, viewController.view.frame.size.height)];
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

        CGContextStrokePath(UIGraphicsGetCurrentContext());
        self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        [self.tempDrawImage setAlpha:opacity];
        UIGraphicsEndImageContext();

        lastPoint = currentPoint;
   // }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];

    [self.nextResponder touchesEnded:touches withEvent:event];
        if(!mouseSwiped)
        {
            UIGraphicsBeginImageContext(viewController.view.frame.size);
            [self.tempDrawImage.image drawInRect:CGRectMake(0, 0, viewController.view.frame.size.width, viewController.view.frame.size.height)];
            CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
            CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush);
            CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, opacity);
            CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
            CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
            CGContextStrokePath(UIGraphicsGetCurrentContext());
            CGContextFlush(UIGraphicsGetCurrentContext());
            self.tempDrawImage.image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
        }

        UIGraphicsBeginImageContext(self.mainImage.frame.size);
        [self.mainImage.image drawInRect:CGRectMake(0, 0, viewController.view.frame.size.width, viewController.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
        [self.tempDrawImage.image drawInRect:CGRectMake(0, 0, viewController.view.frame.size.width, viewController.view.frame.size.height) blendMode:kCGBlendModeNormal alpha:opacity];
        self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
        self.tempDrawImage.image = nil;
        UIGraphicsEndImageContext();
        NSLog(@"mainimage : %@, tempimage : %@", mainImage, tempDrawImage);
}

问题:如何在popover子视图中调用touchesBegan,touchesMoved和touchesEnded?在此先感谢:D

推荐答案

由于Popover是一个单独的视图控制器,因此未调用touch方法.您的touchesBegan和相关方法在错误的位置.

The touch methods are not called because the Popover is a separate view-controller. Your touchesBegan and related methods are in the wrong place.

要使所有功能正常工作,只需创建一个新的UIViewController子类,例如SignatureViewController.

To get everything working, just create a new UIViewController subclass, say SignatureViewController.

然后替换您的第一行:

viewController = [[UIViewController alloc] init];

viewController = [[SignatureViewController alloc] init];

并在SignatureViewController.m中实现您的触摸方法.

And implement your touch methods within SignatureViewController.m

这篇关于我想要一个“绘图弹出窗口",通过单击tableviewcell出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:06