Thanks, Claude. Below is the code for app window resizing:
WindowDidResize Function
(Note that the app has two panes, and on reducing the window width the left (L) pane is hidden - as in Photos for Mac app).
func windowDidResize(_ notification: Notification) {
if let window = self.view.window {
let arrScreens = NSScreen.screens
if arrScreens.count 0 {
let theScreenRect = arrScreens[0]
// Hide the L pane
if (theScreenRect.frame.size.width / 3.0) = window.frame.size.width {
window.setFrame(CGRect(x: window.frame.origin.x,
y: window.frame.origin.y,
width: (theScreenRect.frame.size.width / 3.0),
height: window.frame.size.height),
display: true,
animate: true)
theSplitView?.arrangedSubviews.first?.isHidden = true
if (theSplitView.arrangedSubviews.count) 2 {
theSplitView?.removeArrangedSubview((theSplitView?.arrangedSubviews.first)!)
} else {
theSplitView = orignalSplitView
theSplitView?.arrangedSubviews.first?.setFrameSize(NSSize(width: 250.0, height: window.frame.size.height))
}
} else { // Show the L pane
window.setFrame(CGRect(x: window.frame.origin.x,
y: window.frame.origin.y,
width: window.frame.size.width,
height: window.frame.size.height),
display: true,
animate: true)
theSplitView = orignalSplitView
theSplitView?.arrangedSubviews.first?.setFrameSize(NSSize(width: 250.0, height: window.frame.size.height))
theSplitView?.arrangedSubviews.first?.isHidden = false
}
// Don't allow to resize
if (theScreenRect.frame.size.height / 1.5) = window.frame.size.height {
window.setFrame(CGRect(x: window.frame.origin.x,
y: window.frame.origin.y,
width: window.frame.size.width,
height: (theScreenRect.frame.size.height / 1.5)),
display: true,
animate: true)
} else { // Allow to resize
window.setFrame(CGRect(x: window.frame.origin.x,
y: window.frame.origin.y,
width: window.frame.size.width,
height: window.frame.size.height),
display: true,
animate: true)
}
configurePhotosCollectionViewAfterResize()
}
Configure Photos Collection View
func configurePhotosCollectionViewAfterResize() {
self.collectionViewPhotos.collectionViewLayout?.invalidateLayout()
}
These are only two functions being called when the window is resized. If anything else is needed, please let me know. Maybe we need to add something after invalidating the layout? Not sure. Many thanks.