I am trying to build a UI with a main window that displays some content, and sometimes slides-in a modal view from the right edge of the window. Interaction with the main content must be blocked while the modal is open; however, clicking the main content should close the modal. Here's a mockup:
Please note the user should see only one window. That is, the modal should be nested inside the main window.
I have very little experience with AppKit and Cocoa in general. My approach so far has been to structure my UI like this:
Root region (NSView)
-> MainRegion (NSView)
-> ModalRegion (NSView; toggle hidden and animate the left edge)
and then add subviews to MainRegion and ModalRegion to display content. The problem is that ModalRegion doesn't absorb input events.
What's the AppKit way to build this kind of UI? I mainly just need to know about how the view hierarchy should be shaped and how to block/absorb input events. I think I can figure out the animations myself. Also, the app targets macOS 10.8+, but answers for more recent versions would be helpful, as well.
It’s not really macOS like UI but there are two approaches you could use. In both cases you would use a transparent view to cover the main window and to dismiss the modal view in case of a mouse click. If you need a shadow overlapping the main window as shown in your mockup you will need to use a window attached to the main window as a child window. If this is not the case it would be enough to work with a view which is attached to the contentView of the main window.
All the best.
Related
Several places in OS X (in this example, the Users & Groups pane in System Preferences) have circular image views that allow the user to either drag in an image, like in an editable NSImageView but also allow them to click to show a popover that allows various other choices of image sources.
I have checked the ImageKit framework, but the only thing I found similar is the image taking sheet.
How can I make use of this feature in my own Cocoa applications? I'd imagine it is implemented in some standard framework—but any pointers on implementing something like this would be quite appreciated.
You will have to go down the custom control root as this is not available as a stand alone control.
However you have all the prerequisites.
The circular image view
There a several ways to implement this. You could try using a standard Cocoa button and customise as needed. Although it might just be easier to build from scratch by subclassing NSView. This was you can avoid all the NSCell stuff. I would do the latter.
The popover
Roll your own master-details type view controller to be displayed as the popover's content. In the left have a NSTableView (the master), the right have a NSCollectionView (the details). Below the collection view add some buttons.
I am working on a Cocoa app that consists of 5 views of varying shapes and sizes, some of these views are NSOpenGLViews. I need to have functionality for any of these views to be able to take over the whole window and go into some sort of full screen mode. I originally tried doing this with the method enterFullScreenMode:withOptions: but I ran into trouble when I would try and bring up a dialog window (this would result in a crash). So it seems that I need to scale back my approach a little because I cannot live without these popup dialogs.
My new strategy is to stretch the view that is going into full screen mode so that it takes over the whole view of the screen and then enter into kiosk mode. I was wondering if anyone had tried this type of approach to make a full screen view and if they could offer any advice about best practices for this type of implementation.
My main concern is that I need to preserve the state of the window when I leave full screen mode so I am wondering what would be the best way to hide the other views. Could I just make the other views invisible and then stretch my full screen view to take over the window or would it be better to put the full screen view into a new window and then stretch this new window? My first inclination is that it would be best to keep the full screen view in its original window because it seems this would interfere with event handling less.
I have a cocoa application that has a finder like feel it and is made up of five views. On the left there is a gallery which is a finder like interface to choose a given object. This view stretches across the whole height of the window. Then on the right I have a window for a 3D simulation view and then below it I have three editing views. I would like to be able to press a button and have the 3d view take over the entire window and then go into fullscreen mode, and I am wondering if a more experienced Cocoa developer could give me some advice on how I might want to try this. Should I be removing all the other subviews then resizing the window and 3d view to the size of the screen or would it make more sense to try and just stretch the 3d view to the size of the screen and push the other interface pieces off the screen that way? I would like to eliminate the menu bar when this occurs to have a real full screen feel for me 3d view.
Look up the NSView method enterFullScreenMode:withOptions:. It's easier than you think.
How do I go about adding/removing the window border after it has been created? the window was already designed in interface builder and I would prefer to avoid writing the window purely in code as I am still a long ways before i can say i am experienced with objective-c/cocoa.
Example Program:
a single window with the border initially, a button on it. If you click the button once it makes the boarder disappear and if you click it again then the boarder reappears.
Thanks
As far as I can tell, you can't. You might be able to fake it by taking the content view out of one window and making it be the content view of another window.
I am making an image picker that will display an n by n grid of selectable button when the picker is popped up. This grid of buttons will be contained within an NSWindow but I would like for the window to be close automatically if the user clicks off the screen. Is there a flag that can be set so that when the window looses focus it will be closed automatically?
There are two notifications that you may be interested in: NSWindowDidResignKeyNotification and NSWindowDidResignMainNotification. You can simply register for the one you're interested in in awakeFromNib (or windowDidLoad if you have a custom controller) and then close or hide the window as appropriate when you receive the notifications.
I won't delve too much into whether or not this is a good idea from UI standpoint. But, it might be a better idea to have either an overlay view or a panel for the functionality you describe.
You might check out NSPanel. It's an NSWindow subclass that will hide itself when the app is in the background, and that behavior sounds very similar to what you are looking for.