Effectively, there are very few books for OSX. And I have not found a good one !
You will learn many things with IOS books :
- Swift
- The general API structure (even if syntax if often a bit different) with most objects pretty similar, and mechanisms for actions, delegates, notification…
- XCode
So, it is no waste of time.
But the architecture of a Mac App is pretty different in general: multi windows, menus versus segueing between views in storyboard. And this point of OSX app architecture is very poorly addressed in the books I got.
Personally, I started learning for IOS.
Then, when developing my first OSX App, I used existing code as template.
For your specific point, I think the solution is to use layers
Here is a short example :
- gesture recognizer (panGesture) was added to movableView in IB
- I extracted from an existing code, hope I did not introduce errors.
class AppDelegate: NSObject, NSApplicationDelegate, NSGestureRecognizerDelegate {
@IBOutlet weak var window: NSWindow! // The window created with the app
@IBOutlet weak var movableView: NSView! // One view you can move
@IBOutlet weak var underFixedView: NSView! // a view below, that will not be cleared when movable passes over
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
movableView.layer?.backgroundColor = NSColor.red.cgColor
underFixedView.layer?.backgroundColor = NSColor.green.cgColor
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
@IBAction func panView(sender: NSPanGestureRecognizer) {
let t = sender.translation(in: window.contentView)
sender.view?.frame = NSOffsetRect(sender.view!.frame, t.x, t.y)
sender.setTranslation(NSPoint.zero, in: nil) // Sinon, on garde des coordonnées erratiques et l'image part dans tous les sens
}
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: NSGestureRecognizer) -> Bool {
return true
}
}