我希望用户通过在屏幕上移动手指来绘制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;
}
当我在模拟器上运行它并移动我的手指时,这就是我得到的:
有什么问题?