ios – Set a UIViewController behind one other one as a background picture

Spread the love


I have no idea if is it even posible. I used to be questioning if I may place a second UIImageView behind one other one kind of like a “background reference picture”. I’m doing it programmatically say I’ve MainViewController as the principle UIViewController then I’ve the secondViewController the place the logic of the app takes place and a thirdViewController that may maintain a UIImage.picture because the background for the secondViewController

That is my MainViewController

import UIKit

class MainViewController: UIViewController {
    
  
    
    let canvasView =  secondViewController()
    let canvasBackground  = thirdViewController()
 
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        view.backgroundColor = .systemBlue
        
        canvas()
    }
    
    func canvas() {
        addChild(canvasView)
        
        
        view.addSubview(canvasView.view)
        
        canvasView.didMove(toParent: self)
        
        
    }
}

Right here is my secondViewController

class secondViewController: UIViewController {

 personal let mainImageView: UIImageView = {
       var imageView = UIImageView()
       imageView.backgroundColor = .clear    
       return imageView
    }()
// some extra code and logic implementation

   override func viewDidLoad() {
        tremendous.viewDidLoad()
    }
}

And the thirdViewController

class thirdViewController: UIViewController {
    
    personal let viewLayer: UIImageView = {
       let layerView = UIImageView()
        layerView.backgroundColor = .systemGreen
        return layerView
    }()

    override func viewDidLoad() {
        tremendous.viewDidLoad()

        view.addSubview(viewLayer)
        viewLayer.body = view.bounds

    }
}

I attempted to set the mainImageView.backgroundColor inside secondViewController to .clear to make it clear and have the thirdViewController picture seen within the background.

Any concepts or suggestion on how you can make this work shall be a lot admire it.

Leave a Reply

Your email address will not be published. Required fields are marked *