cocoaautolayoutnsscrollview

Cocoa: When a mouse is connected, resizing width constant causes an AutoLayout issue


Cocoa scrollbars change their style when a mouse is connected. I haven't found a way to see their style.

I have an NSScrollView which I'm hiding by setting its width constraint constant to 0. If the scrollbars are visible and a mouse is connected, on the first time of doing this, it causes an autoresizing issue, and a warning:
Unable to simultaneously satisfy constraints: ...

However, if a mouse is not connected, setting the constant works fine. I guess the wider scrollbar size should be taken into account at some point? What is the correct way of checking for special scrollbar sizes?


Solution

  • After trial & error I found a simple and viable solution. Just set hasVerticalScroller to NO before changing the constant value.

    This doesn't fix all the weird AutoLayout problems, especially when connecting and disconnecting the mouse while the app is running, but at least the constraints don't get broken.