每次用户点击图像时,在可缩放的 UIImageView 上绘制一个小方块。并缩放正方形
Drawing a small square on a zoomable UIImageView each time the User Taps the image. and scaling the squares
我有一个包含图像的 UIImageView。在这种情况下,图像是细菌细胞。我想修改应用程序,以便每次用户点击 imageView 时,都会在 UIImageView 中绘制一个彩色小方块。为了对细胞进行计数。此外,我希望 imageView 可以通过捏合手势进行缩放。到目前为止,我已经能够将 UIImageView 放置在 UIScrollView 中以允许缩放,但我不确定如何将正方形绘制到图像上并让它们随着滚动而缩放。
如果将点击手势识别器附加到图像视图,则可以像这样将正方形添加为该图像视图的子视图,
- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
CGPoint touchPoint = [sender locationInView:sender.view];
UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
square.center = touchPoint;
square.backgroundColor = [UIColor colorWithWhite:1 alpha:0.4];
[sender.view addSubview:square];
}
双指缩放时,方块会随着图像视图一起缩放。
我有一个包含图像的 UIImageView。在这种情况下,图像是细菌细胞。我想修改应用程序,以便每次用户点击 imageView 时,都会在 UIImageView 中绘制一个彩色小方块。为了对细胞进行计数。此外,我希望 imageView 可以通过捏合手势进行缩放。到目前为止,我已经能够将 UIImageView 放置在 UIScrollView 中以允许缩放,但我不确定如何将正方形绘制到图像上并让它们随着滚动而缩放。
如果将点击手势识别器附加到图像视图,则可以像这样将正方形添加为该图像视图的子视图,
- (IBAction)handleTap:(UITapGestureRecognizer *)sender {
CGPoint touchPoint = [sender locationInView:sender.view];
UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
square.center = touchPoint;
square.backgroundColor = [UIColor colorWithWhite:1 alpha:0.4];
[sender.view addSubview:square];
}
双指缩放时,方块会随着图像视图一起缩放。