简体   繁体   English

iPhone:在Image的透明部分设置imageView

[英]iPhone:Set imageView in transparent portion of the Image

I am making an application in which user will be allowed to select a photo frame firstly and after that he/she can have to select 2 photos from gallery for that photo frame (photo frame is an image which coontains two transparent holes in which we have to set the selected photos)and he/she can crop these image according to them.And after he/she is done with cropping a new view will get open with that selected photo frame and those two cropped images will be set in those two transparent whole. 我正在制作一个应用程序,其中允许用户首先选择一个相框,然后他/她必须从图库中为该相框选择2张照片(相框是包含两个透明孔的图像,设置选定的照片),他/她可以根据它们裁剪这些图像。完成裁剪后,他/她将以选定的相框打开一个新视图,并且将这两个裁剪的图像设置为这两个透明整个。 I have finished till the cropping is done. 我已经种完了,直到种完为止。

Question

How to set those two images in the transparent portion so that it will show properly in all the devices and the transparent portion keeps changing according to the photo frames the user will select. 如何在透明部分设置这两个图像,以使其在所有设备中正确显示,并且透明部分根据用户选择的相框不断变化。 我提供的这类相框 在此处输入图片说明

Add new image on view. 在视图上添加新图像。 Add gesture to move and resize (zoom) new image, set perfect position for new image (ie at centre of frame), Then send image view to back side of you main image view. 添加手势以移动和调整(缩放)新图像的大小,为新图像设置完美的位置(即,在帧的中心),然后将图像视图发送到主图像视图的背面。 After that render both view, and make new image with UIGraphicsContext. 之后,渲染两个视图,并使用UIGraphicsContext制作新图像。

I have render code for you. 我为您提供了渲染代码。

    UIGraphicsBeginImageContextWithOptions(self.viewCombineImages.bounds.size, false, 0.0)
    self.viewCombineImages.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()

As per your requirement here you can set 3 ImageView. 根据您的要求,您可以在此处设置3 ImageView。

  1. Image view with Person1 Image. 具有Person1图像的图像视图。
  2. Image View with Person2 Image. 具有Person2图像的图像视图。
  3. Image View with Frame Image. 带有框架图像的图像视图。

so the stack of subview is like UIViewController->UIView->Person Image View1, Person ImageView 2 -> Frame Image View . 所以子视图的堆栈就像UIViewController->UIView->Person Image View1, Person ImageView 2 -> Frame Image View

Like this screenshot. 喜欢这个截图。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

And did not need transparent image position just do both image size half of the frame and set it below frame image view and you can achieve this like my screenshot. 并不需要透明的图像位置,只需将两个图像大小都放在框架的一半,并将其设置在框架图像视图下方,就可以实现此效果,就像我的屏幕截图一样。

If above frame is .png file, it is possible to make transparent those parts. 如果上面的框架是.png文件,则可以使这些部分透明。 I thought you need three UIImageViews. 我以为您需要三个UIImageViews。

upper - decoration frame under - person1's image view / person2's image view. 上部-装饰框架在-person1的图像视图/ person2的图像视图下。

If user select two images, apply each picture on image view. 如果用户选择两个图像,则将每个图片应用在图像视图上。 And adjust those size and coordinate. 并调整这些大小和坐标。 You can use 您可以使用

[person1ImageView setFrame:CGRectMake(x,y,width,height)]; 

Also, you can rotate those by using 另外,您可以使用

person1ImageView.transform =  CGAffineTransformMakeRotation(radians); 

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

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