How can i insert UIView between UIWindow and all the views it has and will contain in Swift

118 Views Asked by At

i have a music player in my project and i want to insert this music player bottom of application. Actually i'm insert it inside UIWindow perfectly but all views goes under this player and it blocks some buttons and table items.

Here is my UIWindow insert code :

        Generate.miniPlayer.translatesAutoresizingMaskIntoConstraints = false
        Generate.miniPlayer.leftAnchor.constraint(equalTo: self.window!.leftAnchor).isActive = true
        Generate.miniPlayer.rightAnchor.constraint(equalTo: self.window!.rightAnchor).isActive = true
        Generate.miniPlayer.bottomAnchor.constraint(equalTo: self.window!.bottomAnchor).isActive = true
        self.window?.addSubview(Generate.miniPlayer)
        self.window?.bringSubviewToFront(Generate.miniPlayer)

Here is my result:

This is the result

Actually what i want: what i want

Thanks a lot!

1

There are 1 best solutions below

1
yasin89 On

When you add yourView to view then yourView will be front of your view. For example you have two view firstView and secondView you have to put like below if you want to add what you want.

view.addSubview(self.firstView)
view.addSubview(self.secondView)

then you have to give constraint like below :

self.secondView.translatesAutoresizingMaskIntoConstraints = false
 self.secondView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
 self.secondView.rightAnchor.constraint(equalTo: view.leftAnchor).isActive = true
 self.secondView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
 self.secondView.topAnchor.constraint(equalTo: self.firstView.bottomAnchor ).isActive = true