Thursday, April 11, 2019

Problem UICollectionViewController When Trying to Use bringSubview Swift 4

Hi guys, I found unique issue when trying to use bringSubview in UICollectionViewController. The method doesn't work if you try like this.

UICollectionViewController has a diffrent to do add subview. Because it's not pure UIViewController itself or parent. It needs to get superview to add a new view.

So basically you do like below and nothing happened or it doesn't work. Don't worry about it, i have a solution for you. It's simple way to do it and don't make you think too much. I find this idea on stackoverflow. I will put the link below.


self.view!.addSubview(something)
self.view!.bringSubview(toFront: something)

So to do trick you need to use superview!.