【问题标题】:Merging multiple UIViews合并多个 UIView
【发布时间】:2017-08-23 01:38:11
【问题描述】:

我目前正在使用以下方法合并多个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 框架内所有视图的快照。

即使其中一个视图具有非静态内容,还有什么方法可以组合多个视图?

【问题讨论】:

    标签: ios swift uiview


    【解决方案1】:
    let cgrect = CGRect(x: 0, y: 0, width: desireWidthOfUIView, height: desireHeightOfUIView);
    
        let view1 = UIView(frame: cgrect)
        let view2 = UIView(frame: cgrect)
    

    我希望这会有所帮助。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多