简体   繁体   English

如何修剪UIImageView中的透明空间?

[英]How to trim transparent space in UIImageView?

I have an app that can drag images anywhere in the view but my problem is that when the other image is behind to the other there is no way to move directly the image behind than moving the above image. 我有一个可以将图像拖到视图中任何位置的应用程序,但是我的问题是,当另一个图像位于另一个图像的后面时,没有比将上面的图像直接移动到另一个图像的方法了。 I found only trimming UIImage but it will display still in UIImageView as rectangle. 我发现仅修整UIImage但它仍将在UIImageView显示为矩形。 I would like to trim the white space so I can click directly behind images. 我想修剪空白区域,以便直接在图像后面单击。

How can I trip UIImageView transparent space? 我如何绊倒UIImageView透明空间?

You can create a bitmap and then examine each pixel. 您可以创建一个位图,然后检查每个像素。 You will find code to do this here. 您将在此处找到执行此操作的代码。 Once you know the exact dimensions you can use a Quartz CGImageRef function to extract out a smaller image from the larger one. 一旦知道确切的尺寸,就可以使用Quartz CGImageRef函数从较大的图像中提取出较小的图像。

That said, you can add a gesture recognizer and use say double tap as a signal to move an image to the bottom of the view stack. 也就是说,您可以添加一个手势识别器,并使用双击作为将图像移至视图堆栈底部的信号。 I believe this is a much better solution if I were to use your app. 我相信如果我要使用您的应用程序,这将是更好的解决方案。

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

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