Reputation: 3653
Hello I added a UIView
to my ViewController
in this way.
self.vWindow = UIApplication.sharedApplication().keyWindow
let mainBound = CGRectMake(0, self.view.frame.size.height-50, self.view.frame.size.width, 135)//CGSizeMake(UIScreen.mainScreen().bounds.size.width, 135.0)
let lblVideo = UILabel.init(frame: CGRectMake(10, 0, 100, 50))
lblVideo.text = "Videos"
lblVideo.textColor = UIColor.yellowColor()
self.vwVideo = UIView.init(frame: mainBound)
self.vwVideo.backgroundColor = UIColor.blackColor()
vWindow!.addSubview(self.vwVideo)
When I go to particular ViewController
from this ViewController
I want to remove this bottom view.I did self.vwVideo.removeFromSuperview()
in viewDidDissappear()
but it doesn't remove my bottom view. How can I do it? Please help me.
Upvotes: 1
Views: 440
Reputation: 2659
You may also declare your label as a global outlet, in a .swift file right below your import statements:
var lblVideo = UILabel()
then you can use lblVideo.removeFromSuperview()
in viewDidDisappear()
Upvotes: 0
Reputation: 35402
Change your code with:
self.vWindow = UIApplication.sharedApplication().keyWindow
let mainBound = CGRectMake(0, self.view.frame.size.height-50, self.view.frame.size.width,135)
//CGSizeMake(UIScreen.mainScreen().bounds.size.width, 135.0)
let lblVideo = UILabel.init(frame: CGRectMake(10, 0, 100, 50))
lblVideo.text = "Videos"
lblVideo.textColor = UIColor.yellowColor()
self.vwVideo = UIView.init(frame: mainBound)
self.vwVideo.tag = 666 // You must tag your video to find after and to destroy it
self.vwVideo.backgroundColor = UIColor.blackColor()
vWindow!.addSubview(self.vwVideo)
After, when you want to destroy your view it's enough to do:
self.vWindow = UIApplication.sharedApplication().keyWindow
self.vWindow!.viewWithTag(666).removeFromSuperview()
Upvotes: 1