简体   繁体   English

将UIView作为子视图添加到UIImageView

[英]Adding a UIView as a subview to UIImageView

I am working on creating a color picker for "iOS". 我正在为“ iOS”创建颜色选择器。 I am using this project, since it does what i want: " This " 我正在使用这个项目,因为它可以满足我的需求:“ This

I want to create a moveable circle ( UIView ) on top of the palette ( UIImageView ). 我想在调色板( UIImageView )的顶部创建一个可移动的圆圈( UIView )。

What I want to do is, while users move the circle, take the touch point and call the method getPixelColorAtLocation(); 我想做的是,当用户移动圆时,取接触点并调用方法getPixelColorAtLocation(); and change the background color of the circle to the color on current point. 并将圆的背景颜色更改为当前点的颜色。 (Seen on most of the color palette/wheels) (在大多数调色板/转轮上都可以看到)

The method getPixelColorAtLocation() is available on a child view. 方法getPixelColorAtLocation()在子视图上可用。 I created a circle with UIView on parent view, the problem is I cant call to getPixelColorAtLocation() from parent view. 我在父视图上使用UIView创建了一个圆,问题是我无法从父视图调用getPixelColorAtLocation()

My question is, Is there anyway to add a UIView as a subView to UIImageView . 我的问题是,是否有将UIView作为子subView添加到UIImageView If I cant, what choices do I have to achieve what I want? 如果我做不到,我要实现自己想要的目标有哪些选择?

是的,您可以这样做。

[myImageView addSubview:sampleView];

An image view is just a subclass of UIView, so you can add subviews to it however you'd like. 图像视图只是UIView的子类,因此您可以根据需要向其添加子视图。 If there's a reason why you can't do so, then you can always make it a subview of the image view's superview, move it to the front, and then use convertPoint:toView: to convert to the image view's coordinate system, then get the pixel color. 如果有原因,您可以始终将其设为图像视图的convertPoint:toView:视图的子视图,将其移至最前面,然后使用convertPoint:toView:转换为图像视图的坐标系,然后获取像素颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM