appkit - Why doesn't overriding `intrinsicContentSize` in `NSView` work for `NSScrollView`? -
i have placed instance of custom class bigview
subclass of nsview
inside nsscrollview
in ib. content size of bigview
computed @ runtime. best practices setting content size?
overriding intrinsiccontentsize
, suggested in the big nerd ranch guide, not seem work -- frame remains @ original size:
class bigview: nsview { ... override var intrinsiccontentsize: nssize { // doesn't work?! return nssize(width: 10000, height: 10000) } ... }
setting frame programmatically (or in ib) work:
class bigview: nsview { ... override func awakefromnib() { ... self.frame = nsrect(x: 0, y: 0, width: 10000, height: 10000) } ... }i
or controller:
class viewcontroller: nsviewcontroller { @iboutlet weak var bigview: bigview! ... override func viewdidload() { super.viewdidload() bigview.frame = nsrect(x: 0, y: 0, width: 1000, height: 1000) } ... }
this can done throughout scrollview's documentview
property:
class viewcontroller: nsviewcontroller { @iboutlet weak var scrollview: nsscrollview! ... override func viewdidload() { super.viewdidload() scrollview.documentview?.frame = nsrect(x: 0, y: 0, width: 1000, height: 1000) } ... }
i suppose 1 use autolayout constraints well.
what doesn't overriding intrinsiccontentsize
work?
the problem when translatesautoresizingmaskintoconstraints enabled in newer versions of appkit default constraints set without considering intrinsic size.
to fix need add constraints manually. first pin position of bigview top left of superview (should nsclipview). go size inspector, , in content compression resistance priority section set intrinsic size placeholder. gives view constraints needs , should work @ runtime.
Comments
Post a Comment