Objective C:在 UIScrollView 上触摸绘图

发布于 2024-12-29 05:01:20 字数 1215 浏览 1 评论 0原文

我正在尝试使用 pageEnabled UIScrollView 制作一个具有不同页面的绘图书应用程序。

我要用什么??触摸事件不起作用。

我在触摸移动之前有这段代码:

    touchSwiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.view];
    currentPoint.y -= 20;

    UIGraphicsBeginImageContext(self.view.frame.size);
    [drawView.image drawInRect:CGRectMake(0, 0, drawView.frame.size.width, drawView.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 0, 0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

    touchMoved++;

    if (touchMoved == 10) {
        touchMoved = 0;
    }

我不知道我需要做什么调整才能实现这一点。

有人吗??

提前致谢。

I am trying to make a drawing book app with different pages on it using a pageEnabled UIScrollView.

What am i gonna use?? touch events are not working.

i have this code before on touches moved:

    touchSwiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.view];
    currentPoint.y -= 20;

    UIGraphicsBeginImageContext(self.view.frame.size);
    [drawView.image drawInRect:CGRectMake(0, 0, drawView.frame.size.width, drawView.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 0, 0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

    touchMoved++;

    if (touchMoved == 10) {
        touchMoved = 0;
    }

i don't have any idea what adjustments i need to do in order to implement this.

anyone??

thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清秋悲枫 2025-01-05 05:01:20

如果您使用评论中提到的 UIPanGestureRecognizer,那么您已将minimumNumberOfTouches 设置为大于 1 的值,对吧?否则,它如何区分绘图和滚动?

我的建议是:

  1. 不要使用 UIScrollView,除非您首先找到一种方法来最终确定触摸是用于绘制还是用于按照用户的意图进行滚动。使用 UIView 的子类,然后可以使用按钮在页面之间移动。
  2. 或者您可以有一个按钮,用于在滚动视图的页面之间切换绘图和滚动(分页)。
  3. 查看此网站,了解一些提示和实际代码来进行绘图 http://www .ifans.com/forums/showthread.php?t=132024

If you are using a UIPanGestureRecognizer as mentioned in your comments, then you have set the minimumNumberOfTouches to something greater than 1, right? Otherwise, how does it tell the difference between drawing and scrolling?

My recommendations are:

  1. Do not use a UIScrollView unless you first figure out a way to conclusively determine if a touch is for drawing or for scrolling as intended by the user. Use a subclass of UIView instead, and then maybe use buttons to move between pages.
  2. Or you could have a button that toggles between drawing and scrolling (paging) between the pages of your scroll view.
  3. Check out this website for some tips and actual code to do the drawing http://www.ifans.com/forums/showthread.php?t=132024
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文