如何在objective-c中按照您的手指制作图像?

Jos*_*800 5 iphone objective-c

你如何在objetive-c中按照你的手指制作图像?

Bro*_*olf 14

  • 创建你的UIView并配置它(或其任何子类,如UIImageView)
  • 将图像的位置设置为用户触摸的位置:

接受触摸事件有四种委托方法,这些方法是从UIResponder继承的任何类的一部分,例如UIView.使用最适合您的委托方法.如果你想要它跟随你的手指,这将是-touchesMoved:

- (void) touchesMoved:(NSSet*)toucheswithEvent:(UIEvent*)event {        
    CGPoint pt = [[touches anyObject] locationInView:self];
    myImageView.center = pt;
}
Run Code Online (Sandbox Code Playgroud)

您可以使用的其他代表方法是:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)

我写了一个示例应用程序,它完全符合您的要求.这是一个绘制Quartz 2D图形的演示,但它会绘制一个红色正方形和黑色圆圈,您可以拖动手指,并且应该足够简单:

替代文字http://brockwoolf.com/shares/stackoverflow/3445494/screen.png

下载Xcode项目(32kb)