swiftmacosnscollectionview

Why is NSCollectionView cut off?


I have a NSCollectionView inside of NSScrollView inside of a NSSplitView. The CollectionView contains NSImageViews. Everything works fine, but the CollectionView is clipped (but without scroll bars).

This is the result:

clipped NSCollectionView

(There are 5 sections. Section 1 has one image. Section 2 (clipped) has two images. Section 3 (not visible) has three images and so on).

I can't understand why some of the CollectionView's content is cut off. When I select the CollectionView, there are "resize squares" (what is the name of this little squares?), but they are inactive:

NSCollectionView

When I select the CollectionViewFlowLayout I can see exactly the area that is visible in the running app:

CollectionViewFlowLayout

I can't unterstand that behaviour:

How can I get the CollectionView to display all the images completely?


Solution

  • According to https://stackoverflow.com/a/62973012/4213887 I've added the following Code to the ViewController that owns the CollectionView:

    override func viewDidAppear() {
        self.view.setFrameSize(NSSize(width: self.view.frame.size.width, height: self.view.frame.size.height + 1))
    }
    

    Now everything is OK:

    correct behaviour

    Some say it could be an issue only in macOS 10.13 and 10.14, but at the moment I am not able to test other versions.