Getting a UIImageview to fill the entire screen

0

I am working with TableViewControllers and in my first TableView I have decided that I should see an image that occupies the whole length and width of the screen in such a way that it does not show what is behind if not until the image disappears (This part is already achieved). I'm doing it this way:

   override func viewDidLoad() {
    super.viewDidLoad()
    let nav = self.navigationController?.navigationBar
    nav!.hidden = true
    let bounds = UIScreen.mainScreen().bounds
    let screenHeight = bounds.size.height
    let screenWidth = bounds.size.width


    let dynamicImage=UIImageView(frame: CGRectMake(0, 0, screenWidth, screenHeight))
    dynamicImage.backgroundColor=UIColor.greenColor()

    self.view.addSubview(dynamicImage)
  UIView.animateWithDuration(0.2, delay: 10.0, options: [] , animations: {() -> Void in
        dynamicImage.alpha = 0.0
        }, completion: {(true) -> Void in
            dynamicImage.removeFromSuperview()
            nav!.hidden = false
    })

The fact is that the screen looks like this:

and I do not occupy the entire height of the screen, since you can still see the top bar, in addition to that if I touch the screen and slide upwards scroll scrolls the UIImageview upwards. What I intend is that the UIImageview contains an advertising image that lasts x d seconds with the screen blocked however I have two problems:

  • I do not take up the whole screen
  • The UIImageview can be manipulated (ie scroll down according to the scrolling scrollview.
  • Thanks

        
    asked by Víctor Gonzal 30.04.2016 в 00:43
    source

    1 answer

    1

    You must be clear that the bar above is the UINavigationBar of a UINavigationController and that as such, it is not the UIViewController where you are adding the image. Or put another way, you are not adding the UIImageView to the UINavigationController and for that reason the screen does not occupy you. You must be clear that the UINavigationController is a container that has implemented a queue with the viewControllers that you are adding and removing. In your case, you are adding the image in UIViewController that is visible at that moment in UINavigationController .

    To work properly, you must do the following:

    // Añadimos imagen
    let dynamicImage = UIImageView(frame: UIScreen.mainScreen().bounds)
    dynamicImage.backgroundColor = .greenColor()
    navigationController?.view.addSubview(dynamicImage)
    
    // Ocultamos imagen
    UIView.animateWithDuration(0.2, delay: 10.0, options: [], animations: {
    
        dynamicImage.alpha = 0.0
    
    }) { (completed) in
    
        dynamicImage.removeFromSuperview()
    
    }
    
        
    answered by 30.04.2016 / 11:37
    source