0

我希望用户通过在屏幕上移动手指来绘制 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;
}

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

在此处输入图像描述

怎么了?

4

0 回答 0