查找关于UIImage大小的子视图的原点 [英] Find the origin of subview with respect to UIImage size

查看:66
本文介绍了查找关于UIImage大小的子视图的原点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是层次结构:

-- ViewController.View P [width: 375, height: 667]
---- UIImageView A       [width: 375, height: 667]
                         [A is holding an image of size(1287,1662)]
---- UIImageView B       [width: 100, height: 100]
                         [B is holding an image of size(2400,982)]

注意:B不是A的子视图.在应用程序中,B是可拖动的.我正在尝试合并两个A和B,这两个位置分别是A [背景]和B [前景].

Note: B is not a subview of A. In the app, B is draggable. And I am trying to merge two A and B where positions are, A [background] and B [foreground].

我想找到B的确切位置,以使合并后它与我拖曳&的位置相同.放下.

I want to find the exact position of B such that, after merging it will be at the same position where I dragged & dropped.

  1. 我已经编写了所有拖放代码.
  2. 我找不到与A合并的B的合适位置.

以下是问题屏幕截图:

显示B的初始位置.

这是拖放后B的新位置.

合并后B的位置错误.

任何帮助将不胜感激.

谢谢.

注意! :已在Google搜索中建立了附加的示例样本"以及屏幕截图中的签名".我仅用于演示目的.

Attention! : Attached images Sample Later and a Signature inside the screenshots has been founded in Google search. I have used for demonstration purpose only.

推荐答案

在合并时,我需要使用imageView的(A)frame.size而不是A.image.size来获取正确的位置.

I needed to use imageView's (A) frame.size instead of A.image.size to get the right location while merging.

代码如下:

func mixImagesWith(frontImage:UIImage?, backgroundImage: UIImage?, atPoint point:CGPoint, ofSize signatureSize:CGSize) -> UIImage {
    let size = self.imgBackground.frame.size
    //let size = self.imgBackground.image!.size
    UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
    backgroundImage?.draw(in: CGRect.init(x: 0, y: 0, width: size.width, height: size.height))
    frontImage?.draw(in: CGRect.init(x: point.x, y: point.y, width: signatureSize.width, height: signatureSize.height))
    let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    return newImage
}

这篇关于查找关于UIImage大小的子视图的原点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆