2

I have a main View and a subView. Everything worked perfectly: I click on a button "Open" on the View, that displays the subView above everything, and I can close the subView.

I decided to add an adBannerView at the bottom of my app. When I run the app, the adbannerView works perfectly: the add is loaded into a frame at the bottom of my App. But when I click on the button "Open", the subView doesn't display above everything anymore. It displays UNDER everything on the View. Can you help me solve this issue? Thank you so much!

Here is the code I've implemented for the adBannerView and the subView (I have removed other code not relevant for my problem):

import UIKit
import iAd

class ViewController: UIViewController, ADBannerViewDelegate {

@IBOutlet weak var boutonChangerPays: UIButton!
@IBOutlet weak var cadrePays: UIView! 
@IBOutlet weak var bannierePub: ADBannerView!

// Chargement initial de la Vue principale
override func viewDidLoad() {

    super.viewDidLoad()

    // Cadre Pays
    self.cadrePays.hidden = true

    // Banniere Ad
    self.canDisplayBannerAds = true
    self.bannierePub.delegate = self
    self.bannierePub.hidden = true
}

//*************************
// ADBANNERVIEW
// BANNIERE  DE  PUBLICITE
func bannerViewWillLoadAd(banner: ADBannerView!) {
    NSLog("bannierePub se charge")
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    self.bannierePub.hidden = false
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
    NSLog("bannierePub a finit de se charger")
}

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    NSLog("Action pendant que la bannière se charge")

    return true
}

//**************************************************************************
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// Retour de l'écran de détail
override func viewDidAppear(animated: Bool) {
    // Indicateur d'Activité : caché
    self.indicateurActivite.stopAnimating()
    self.indicateurActivite.hidden = true
}

// Bouton Changer Pays
@IBAction func boutonChangerPays(sender: UIButton) {

    // On affiche la Vue des Pays
    self.cadrePays.hidden = false
}       
}
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
Jeanne Merle
  • 37
  • 1
  • 1
  • 6

2 Answers2

0

You can call this function to bring subview above everything.

self.view.bringSubviewToFront(self.yourSubviewName)
Munahil
  • 2,381
  • 1
  • 14
  • 24
  • I have tried this, but It doesn't work. // Bouton Changer Pays @IBAction func boutonChangerPays(sender: UIButton) { // On affiche la Vue des Pays self.cadrePays.hidden = false self.view.bringSubviewToFront(cadrePays) } – Jeanne Merle Aug 10 '15 at 19:44
0

Surprisingly, I've found the solution by trying this :

In the function of my button click, i add this code :

self.view.addSubview(self.cadrePays)

And it brings the subview back on the bottom ! I hope that will not "create" a lot of subviews stacked one other anotherone !

The constraints of position are not at all respected, I had to center it with :

override func viewDidLayoutSubviews () {
self.cadrePays.center = self.view.center
}

The SubView is centered horizontaly, but not vertically, but now I think I'm very close to the solution.

Hope It will help other peole !

Jeanne Merle
  • 37
  • 1
  • 1
  • 6