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.
Related
To keep things simple, let's say I have a window containing a single view, which has auto layout constraints binding all 4 sides to the window container view with offset 0. And assume that this view also has a constraint setting its aspect ratio to a constant value. If I resize the window manually, then then window nicely maintains the desired aspect ratio. But if I click the little green zoom widget, then the window fills up the whole screen, regardless of the aspect ratio, with part of the view being above the top of the screen. Is there some way I can make zooming resize the window as big as it can be, without violating auto layout constraints?
I couldn't very well detect this problem in the delegate method windowWillResize:toSize:, because that doesn't tell me which screen it's thinking about putting the window on. I could try to fix the window size in the windowDidResize: delegate method, at which time I do know what screen it's on, but I'm not sure exactly how to do that without reinventing Auto Layout's wheel.
Apparently someone thinks I wasn't explicit enough, so I'll try again. Steps to reproduce:
In Xcode, create a new macOS App project using XIB interface.
Open MainMenu.xib and select the window.
Reshape the window to be approximately square.
Using the Attribute Inspector, set the Full Screen behavior for the window to Auxiliary Window.
Drag an Image View from the library and drop it in the window.
In the Attributes Inspector, set the image view to show the NSComputer image and scale axes independently.
Expand the image view to fill up the window content area.
With the image view selected, click the button to add new layout constraints.
Add 5 constraints, binding the 4 sides to the container, and setting the aspect ratio. (see screen shot)
Build and Run.
Observe that if you resize the window by dragging an edge or corner, the aspect ratio remains fixed.
Click the green zoom widget in the title bar of the window, and observe that the window expands without regard for the aspect ratio constraint, cutting off part of the image.
I just set up a test project exactly as you specified, and when I invoke the window zoom widget, the window expands and retains its aspect ratio i.e. it works as expected. The only thing I can think of that might be causing your issue: maybe your content hugging and content compression resistance priorities are at odds with your constraints? Mind you, I just left them at the default values and it worked fine. Unfortunately Mac/AppKit development (esp. when using IB) is rife with these kind of odd bugs and weird behaviour, probably because Apple has not given it any love in years, so bugs creep in/fester and they are clearly so DONE with developing UI the 'old fashioned way'. (Using SwiftUI to make a Mac app is just as frustrating, in different ways, so I'll stick with what I know). FYI, I used Xcode 13.4.1 to create this test project. Good luck!
My app does not fill the entire screen. It is a rectangle, lets say, 1000x500 pixels. When the app is on the middle of the screen and I show a popover it appears like this:
What is ugly, half of popover outside the app area.
But if the app is near the left edge of the screen, then it appears the way I want, like this:
What is pretty, all the popover contained inside the app's area.
Is there a way to force the popover to always appear like this second case, inside the app's area?
As far as I know you have very little control on how a popover is displayed. Apple reserves themselves the right to make changes on how to display popover's and this would not be possible if you were in total control. You can define the preferred edge and the preferred width and pretty much anything else is up to the system. If you need more control yourself, you need to draw the whole thing yourself (which is possible, just a a lot of work) or use some third party framework.
I need to take a screenshot of whole storyboard as an image. Is that possible? I need it to give to my designer.
Ideally I'd like to get 1 big image, make some changes (number views, etc) and save it as JPG
Xcode doesn't have any features for printing or exporting an image of your storyboard. (Though that might make a good feature request to send to Apple.)
Your best bet is to resize your project window as large as possible (and hide the navigator and utility sidebars) and take a screenshot. You might be able to employ a trick or two in getting everything to fit:
If you're on a Mac with a Retina Display, change your screen resolution to one of the "more space" options so your Xcode window can be bigger. (For example, on a 5K iMac you can choose the "looks like 3200 x 1800" size, which renders a 6400 x 3600 screen and downscales it to fit the actual display hardware.)
Zoom out on the storyboard with the Editor > Canvas > Zoom menu commands. In Xcode 8, the zoomed-out storyboard uses the same rendering/editing engine as the regular-size view — which means that on a Retina display, your shrunken-down views will still be legible.
Resize the window larger than the screen, then take a window screenshot (Cmd-Shift-4, then spacebar, then click the window). You can do this with AppleScript:
tell application "Xcode" to set bounds of front window to {0, 0, 4000, 3000}
But that'll still limit its height to that of the screen (minus menubar and Dock). You can drag the window to the bottom of the screen and edge-resize it upward to get some extra height, though.
One more thing: Since the beginning of storyboards (way back in Xcode... 5, I think?), you've never needed to have "one storyboard to rule them all" in your project. In fact, there are lots of reasons why it might make sense to break your app into multiple storyboards. And of course, if you have multiple storyboards, you can screenshot them separately and integrate them however you like for a design presentation.
Using multiple storyboards used to mean you couldn't segue between view controllers in separate storyboards (you'd have to instantiate and present view controllers programmatically), but since Xcode 7 you can insert a "Storyboard Reference" in one storyboard to link to a view controller in a different storyboard. And if you have a big storyboard you want to break up, there's a tool for that. (Select some view controllers, choose Editor > Refactor to Storyboard...)
Let's say we have two screen scenario and a NSWindow,
positioned at the edge of screen 1.
A part of that of that window is also shown on screen 2.
What I would like to achieve, is to draw the window only on screen 1 and to not show the rest on screen 2.
The reason for that is that's some kind of a specially behaving mini window, not a usual one.
Is it possible to assign a certain NSScreen to draw the window on, only?
Two very different approaches:
Use Mavericks: What you looking for sounds like the behaviour of Mavericks' "screens have separate spaces" mode. In this mode a window is never drawn on two screens except during drag operations, at other times the window is draw on one screen with any areas protruding onto adjacent screens clipped. So if you can restrict use to 10.9 this may save you some work.
Borderless Windows: You can create a borderless non-opaque NSWindow, just set the appropriate flags. This is how applications create non-square windows, the visible area of the window is now entirely up to you. Now just clip your drawing to the area on one screen using the standard clipping support. You won't have a standard title bar or controls, unless you emulate them yourself, so you have to implement drag yourself etc. You say you have "some kind of a specially behaving mini window, not a usual one" so that may not be an issue.
Not that I've heard of.
What you could do though is restricting the position of the window e.g. via a NSWindowDelegate and windowDidMove: to listen to position changes and reposition the window appropriately.
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.