Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: how to push ViewController over current context?

I have VC and I want to push it and to see the VC that under it.

I can do it if I present if modally (Display clearColor UIViewController over UIViewController)

But is it possible to implement this feature via push VC? Or I need to create custom transition ?

like image 637
Igor Bizi Avatar asked Oct 20 '15 16:10

Igor Bizi


1 Answers

To expand on Wain's comment:

  • you can render the parent view in a UIImage;
  • you then set this image as the background of your new view.

Here is a possible implementation in Swift:

override func viewDidLoad() {

    super.viewDidLoad()

    // render parent view in a UIImage
    UIGraphicsBeginImageContext(self.view.bounds.size);
    self.parent?.view.layer.render(in: UIGraphicsGetCurrentContext()!)
    let viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // add the image as background of the view
    self.view.insertSubview(UIImageView(image: viewImage), at: 0)
like image 103
Arnaud Avatar answered Nov 15 '22 03:11

Arnaud