触摸移动时绘制imageView - objective-c

时间:2013-07-03 21:14:10

标签: objective-c image cocoa-touch

我希望用户通过在屏幕上移动手指来绘制UIImageView。当用户将手指向右移动时,宽度会改变等。这是我的代码:

这是在drawrect方法中:

if (touchmoved)
{
rectImage = [[UIImageView alloc] initWithFrame:CGRectMake(startPoint.x, startPoint.y, (movePoint.x-startPoint.x), (movePoint.y-startPoint.y))];
rectImage.backgroundColor = [UIColor clearColor];
rectImage.layer.borderColor = [UIColor blackColor].CGColor;
rectImage.layer.borderWidth = 2.0;
[self addSubview:rectImage];
touchmoved = NO;
}

此处touchMoved方法中touchmoved设置为YES:

if ((movePoint.x > startPoint.x)&&(movePoint.y >startPoint.y))  //startPoint in the locationinView point in the touchesBegan.
{
    touchBegan = YES;
}

当我在模拟器上运行它并移动我的手指时,这就是我得到的:

enter image description here

有什么问题?

0 个答案:

没有答案