-3

I want to invalidateLayout() of the custom UICollectionView when the bounds are changed. I know that I can call this method from the controller using viewWillLayoutSubviews(). But since I want to make this custom UICollectionView as a framework, I want to implement the function without being dependent to the controller.

If I try to invalidateLayout() inside override open func layoutSubviews() then I get an infinite loop.

What is the best way to implement what I want with the constraints give?

Ham Dong Kyun
  • 756
  • 4
  • 28

1 Answers1

0

View Controllers have this method -:

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
        collectionView.collectionViewLayout.invalidateLayout()
    }
Tushar Sharma
  • 2,839
  • 1
  • 16
  • 38
  • Are you sure it is the UICollectionView that has this method? Can you give me the link to the Apple Developer Documentation? I couldn't find it – Ham Dong Kyun Jul 30 '17 at 05:56
  • @Ham Dong Kyun its a view controller method sorry for mistake . You can just type it out and you will get one. – Tushar Sharma Jul 30 '17 at 06:00
  • Sorry, but I explicitly explained that I do not want to link it to the controller. – Ham Dong Kyun Jul 30 '17 at 06:00
  • @HamDongKyun what you meant by link to controller? Please explain . – Tushar Sharma Jul 30 '17 at 06:02
  • I want the code to be in the UICollectionView subclass and not linked to any UIViewControllers. – Ham Dong Kyun Jul 30 '17 at 06:03
  • @Ham Dong Kyun I am not getting what are you trying to achieve with that, but this is the only good way you can determine rotation and update layout without any burden. – Tushar Sharma Jul 30 '17 at 06:05
  • I want to make a UI Framework as explained in the question above. Within this framework I would like to provide a collection view that will resize the cell size when the device is rotated. Due to the above request, I can not link to any UIViewController to detect the rotation. – Ham Dong Kyun Jul 30 '17 at 06:09