This function (for macOS) will take any NSControl that is based on NSView (which is just about all of them) and return an NSImage snapshot of the control
func takeSnapShot(_ tempCtrl : NSView) -> NSImage {
private var osCtrlImage : NSImage? = nil
if let rep = tempCtrl.bitmapImageRepForCachingDisplay(in: tempCtrl.bounds) {
tempCtrl.cacheDisplay(in: tempCtrl.bounds, to: rep)
osCtrlImage = NSImage(size: tempCtrl.bounds.size)
osCtrlImage!.addRepresentation(rep)
}
return osCtrlImage
}
Yeah, it’s pretty cool that function. I find really useful for animating the changing of a preferences pane, so you grab the current view, throw it into a new view, line 'em both up and use Core Animation to transition between the old state and the new.
but this is what a tabpanel produces… notice the body of the control is there, as is the outline of where the “tabs” should go, but not the tabs themselves
I don’t know how to do it in Xcode, how I’ve done it via Xojo is at runtime and list out all the attached sub NSViews.
Its like the NSTableView and NSTextView are wrapped in NSScrollViews, but we kinda ignore those. So I wondered if that might be the case with the Tab Panel.
In recent years, it’s gotten pretty flaky with displaying controls, I often end up with a window with controls no longer visible in the IDE. I just assumed it was another bug that lost out in favor or “2.0 All The Things™”.
I actually noticed it the other day in Xojo 2019r1.1 to see what happened if I duplicated the same control.
So in my Swift app I’m going to try and replicate it using a box and seg ctrl. this app just needs a visual facsimile of the control, not a real live one. As it is, this apps does GUI displays for macOS, iOS and tvOS, so there are a number of the non-macOS controls I have to “draw manually”