【发布时间】:2023-08-15 01:13:02
【问题描述】:
目前我正在为一个拼贴应用工作。我想画拼贴画框,然后我需要从相机胶卷或相机中添加图像。我需要以下类型视图
我添加了 5 个 UIImageViews。为了绘制形状,我添加了 UIBezierPath,例如 imageview1
UIBezierPath *path1 = [[UIBezierPath alloc] init];
[path1 moveToPoint:CGPointMake(0, 0)];
[path1 addLineToPoint:CGPointMake(150, 0)];
[path1 addLineToPoint:CGPointMake(0, 150)];
[path1 addLineToPoint:CGPointMake(0, 0)];
UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(140, 0, 160, 300)];
imgView1 . tag = 2;
imgView1 . userInteractionEnabled = YES;
imgView1. backgroundColor = [UIColor greenColor];
CGPathRef borderPathRef2 = [path1 CGPath];
CAShapeLayer *borderShapeLayer2 = [[CAShapeLayer alloc] init];
[borderShapeLayer2 setPath:borderPathRef2];
[[imgView1 layer] setMask:borderShapeLayer2];
imgView1.layer.masksToBounds = YES;
[borderShapeLayer2 release];
[view1 addSubview:imgView1];
像这样我对所有 5 个都做了。但是在添加 imageView5 之后,在所有其他 4 个视图上都没有检测到触摸,因为它的框架与其他四个 imageview 重叠。
所以我不知道如何设计这个。我需要通过触摸操作将图像添加到所有图像视图。
请帮助我。如果有人对此有任何想法,请分享。
提前致谢。
以下是来自 Insta Collage 应用程序的示例 2。
【问题讨论】:
-
你为什么不使用按钮。你有背景图片以及动作?
-
如果我要使用按钮,那么只有 imageview5 会执行按钮操作。
-
您能分享一下您想要实现的确切图像设计吗?该框架显示了实现相同目标的几种替代方法。为了具体到您的需要,张贴链接
-
如果你只需要恢复用户交互,在你添加其他imageviews之后,添加这个
[self.view bringSubviewToFront:imageView5];,然后你会得到它 -
这取决于用户。如果用户想先在 imageview1 上添加图像,或者可能是 imageview 5。就是这种情况。
标签: iphone ios uiimageview uibezierpath