2

So I have been going through my code over and over and searching online for a solution to this problem and I am stuck. Nothing that I can find online has any information on why the screen would load and then turn black. The code modally presents another view that has a UIImageView inside of it. There is an image (.png file) that should be loading in the image view and you can see the image while the view is being presented modally, but as soon as the view slides into place the whole view turns black. Also you can see the image in the storyboard and it shows it correctly, it is only in the simulator where the image immediately turns black.

Here is the code of the view controller that is presented:

import UIKit

class MenuViewController: UIViewController
{
    @IBOutlet var imageView: UIImageView!

    override func viewDidLoad()
    {
        super.viewDidLoad()
        // Do any additional setup after loading the view
        let backgroundImage: UIImage! = UIImage(contentsOfFile: "behind_alert_view.png")
        imageView.image = backgroundImage;
    }


}

I also tried using the function UIImage(named: "behind_alert_view.png"). Any help would be greatly appreciated!

Olyve
  • 701
  • 1
  • 8
  • 27
  • Just to test and see if the image is disappearing and showing your VC's background, in the VC that turns black add this to your viewDidLoad func: view.backgroundColor = UIColor.whiteColor() If the black is your view's bg color, then it should now turn white. – davidrayowens Sep 03 '14 at 16:29
  • Yes I tried that and instead of it being black it turns white and the image is no longer visible. The image appears only when the view is sliding up and then it turns white. – Olyve Sep 03 '14 at 17:36
  • Is this a background image for your modally presented view? And if not, does it appear in the top left instead of where you place it in the IB? – davidrayowens Sep 03 '14 at 17:41
  • Yes it's a background image. I was trying to create a modally presented menu that had a semi transparent background to show the contents of what was underneath. The tutorial I was following suggested using an image that was semi transparent, such as that one, and then putting the menu over top of the image. – Olyve Sep 03 '14 at 17:50
  • I wonder if it could be that the menu view controller is not being popped onto the stack meaning there wouldn't be anything underneath to show? – Olyve Sep 03 '14 at 17:52
  • Could you post that link so I have a better understanding? Not sure on the semi transparent part, but try this for a background on the view, and we'll work from there: view.backgroundColor = UIColor(patternImage: UIImage(named:"fileinimageassets.png")) – davidrayowens Sep 03 '14 at 17:52
  • http://stackoverflow.com/questions/16230700/display-uiviewcontroller-as-popup-in-iphone that is the link to the tutorial I was following – Olyve Sep 03 '14 at 17:55
  • Tried the suggestion and it results in the same thing – Olyve Sep 03 '14 at 17:57
  • Yeah, I'm understanding a bit more with the link, gonna run through it here to see if I can get it to work and let you know. – davidrayowens Sep 03 '14 at 17:58
  • I even checked out the MZFormSheetController project that was listed and it looks great I was just having difficulty figuring out how to use it cause it does not seem to be documented very well in my opinion. It assumes that you are very familiar with obj-c and I am somewhat new to iOS development still – Olyve Sep 03 '14 at 18:09
  • I'm getting the same thing you're getting, but...I used a UIView instead of a UIImage, so what i'm seeing now is, after a few seconds, the alpha (opacity) is reset to 1 instead of staying at what we set. Gonna keep working on it. – davidrayowens Sep 03 '14 at 18:12
  • Thanks for the help! Glad to see that its not just me or my system! – Olyve Sep 03 '14 at 18:14

1 Answers1

3

First, in your SecondViewController, set the main view's background color to clearColor, and add a second full-size view inside it. Set the second view's background color to your desired color, for example "darkGrayColor" and set it's alpha to 0.3.

Then, inside of your Interface Builder, click on the segue between FirstViewController and SecondViewController and under for "Presentation" choose "Over Current Context".

enter image description here

Alternatively, the following code should do the same thing. But in Xcode 6 Beta 7, I could not get it to work successfully:

self.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
davidrayowens
  • 1,562
  • 2
  • 13
  • 23
  • Wow thank you so much!! That fixed it completely! I have been struggling with this for almost two weeks trying to figure out how to do this! :D Now I can finally move on with the project! – Olyve Sep 03 '14 at 19:00
  • Very glad it helped! Love the idea...think I'll use it myself! Cheers! – davidrayowens Sep 03 '14 at 19:01