合并多个UIViews

时间:2017-08-23 01:38:12

标签: ios swift uiview

我目前正在使用以下方法合并多个UIView

targetImageView.addSubview(view1)
targetImageView.addSubview(view2)
UIGraphicsBeginImageContextWithOptions(targetImageView.bounds.size, false, UIScreen.main.scale)
targetImageView.layer.render(in: UIGraphicsGetCurrentContext()!)
let combinedImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()

如果所有视图都是静态的,则此方法很有效。但是,如果其中一个视图有动画内容,比如视频,动画或gif ......那么这个方法就行不通,因为我认为它只是拍摄了targetImageView帧内所有视图的快照。

即使其中一个视图具有非静态内容,组合多个视图的另一种方法是什么?

1 个答案:

答案 0 :(得分:0)

let cgrect = CGRect(x: 0, y: 0, width: desireWidthOfUIView, height: desireHeightOfUIView);

    let view1 = UIView(frame: cgrect)
    let view2 = UIView(frame: cgrect)

我希望这有帮助。 :)