gpt4 book ai didi

ios - 我想要通过单击 tableviewcell 出现 "drawing popover"吗?

转载 作者:行者123 更新时间:2023-11-29 01:07:57 25 4
gpt4 key购买 nike

当我点击一个 tableviewcell 时,我想要一个带有签名“绘图”的弹出窗口。喜欢这张照片: enter image description here

这是我的代码:

- (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 中被很好地调用,但是当我点击 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 subview 中调用 touchesBegan、touchesMoved 和 touchesEnded?提前致谢:D

最佳答案

触摸方法不会被调用,因为 Popover 是一个单独的 View Controller 。您的 touchesBegan 和相关方法放错了地方。

要使一切正常,只需创建一个新的 UIViewController 子类,比如 SignatureViewController

然后替换你的第一行:

viewController = [[UIViewController alloc] init];

viewController = [[SignatureViewController alloc] init];

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

关于ios - 我想要通过单击 tableviewcell 出现 "drawing popover"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36135820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com