目标 C:在 UIScrollView 上用手指绘图 [英] Objective C: Drawing with Fingers on UIScrollView

查看:26
本文介绍了目标 C:在 UIScrollView 上用手指绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个画板应用程序.

I am trying to make a sketch pad app.

我使用 UIScrollView 进行分页,使用 UIImageView 进行绘图.

I used UIScrollView for paging and UIImageView for the drawing.

我将 UIImageView 放在 scrollView 的顶部,但它没有添加到 UIScrollView 所以它不会滚动.

I put the UIImageView on top of the scrollView but it's not added to UIScrollView so it will not scroll.

现在的问题...

它不是在写...

[scrollView setScrollEnable:YES];
[scrollView setUserInteractionEnabled:YES];

我需要将它设置为 NO 并使用一个按钮来编写,

i need to set it to NO with the use of a button for it to write,

有没有办法让我不用任何按钮就可以同时滚动和书写??

is there a way that i can scroll and write at the same time without using any button??

推荐答案

这绝对不是构建此类应用程序的正确方法.

This is definitely not the correct way of building such an application.

A UIScrollView 用于滚动内容而不是用于绘图.而且您也不需要 UIImageView 来绘制内容,一个简单的 UIView 就足够了.

A UIScrollView is meant for scrolling content not for drawing. And you don't need a UIImageView to draw content either, a simple UIView would be enough.

在这里你最好的办法是创建一个 UIScrollView 并禁用它的滚动,因为你将用两根手指处理它,而绘图将被处理平移另一个手势识别器.

Here you're best bet would be to create one UIScrollView and disable it's scrolling because you'll be handling it with two fingers, while the drawing will be handled pan another gesture recognizer.

UIPanGestureRecognizer *twoFingerScrolling  = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onTwoFingerScroll:)] autorelease];
[twoFingerScrolling setMinimumNumberOfTouches:2];
[twoFingerScrolling setMaximumNumberOfTouches:2]; 
UIPanGestureRecognizer *oneFingerDraw   = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onOneFingerDraw:)] autorelease];
[oneFingerDraw setMinimumNumberOfTouches:1];
[oneFingerDraw setMaximumNumberOfTouches:1];

[yourScollView addGestureRecognizer:twoFingerScrolling];
[yourScollView addGestureRecognizer:oneFingerDraw];

稍后在您的代码中,您可以轻松处理这两个事件,即滚动:

And later on in your code you can easily process both events, the scrolling:

- (void)onTwoFingerScroll:(UIPanGestureRecognizer*)sender
{
   // Calculate the content offset from the shifting that occured
   //[yourScrollView setContentOffset:theContentOffset]
}

和绘图(可以通过 Quartz 工具包)

- (void)onOneFingerDraw:(UIPanGestureRecognizer*)sender
    {
       // Processing the drawing by using comparing:
       if (sender.state == UIGestureRecognizerStateBegan) 
         { /* drawing began */ }
       else if (iRecognizer.state == UIGestureRecognizerStateChanged)
         { /* drawing occured */ }
       else if (iRecognizer.state == UIGestureRecognizerStateEnded) 
         { /* drawing ended /* }
    }

希望这会有所帮助.

这篇关于目标 C:在 UIScrollView 上用手指绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆