Sliding Menu in Mac App - objective-c

How can I make a sliding menu like (as an example) Sparrow's main email menu?
In the case of Sparrow:
It's a column of buttons that essentially slide to reveal a NSScrollView (with custom NSTableView?) with various folders inside (inbox, sent, etc). Clicking on a different account causes that account to slide up to the top and reveals the various folders inside.
How could I go about doing a menu similar to this?

There is some fairly cool Apple sample code here to deal with table views and animation (uses stuff that is generally only available as of Mac OS X 10.7 however):
https://developer.apple.com/library/mac/#samplecode/AnimatedTableView/Listings/ATPopupWindow_m.html%23//apple_ref/doc/uid/DTS40008863-ATPopupWindow_m-DontLinkElementID_26
Also, for basic window resize animation you can use the setFrame:display:animate: method of NSWindow.

Related

Resize and reposition window to span all monitors

Hi all I am working on a small cross-platform hobby/educational project which takes screenshot of all monitors and overlays all monitors with one wide window. Now on Windows and GTK systems this is no problem. But I am having issues on OSX:
First major issue is that the window is not covering the non-work areas of the dock and the menubar at top.
It won't resize to span multiple monitors.
Is there any programattic way to accomplish this? Users really like when a screenshot is taken that it overlays all monitors with the capture and then they crop and click upload to image service etc. I just want to bring them the same experience on OSX.
Thanks
With OS X 10.9, Apple introduced a feature called "Displays have separate Spaces". See the Mission Control pane of System Preferences. It's on by default.
When that is on, no window can span multiple monitors. Even if it's programmatically set with an frame that does, it will only appear on the screen that contains the most area of the window. The window will be clipped to the frame of that screen.
So, you have to create a separate window for each screen.
From the 10.9 AppKit release notes:
Spaces and Multiple Screens
In 10.9, we have added a feature where
each screen gets its own set of spaces, and it is possible to switch
between spaces on one screen without perturbing the spaces on the
other screens. In this mode, a fullscreen window uses one screen, and
leaves the contents of any other screens unchanged. …
When this feature is enabled, windows may not visibly span displays.
A window will get assigned to the display containing the majority of
its geometry if programmatically positioned in a spanning position. A
window will get assigned to the display containing the mouse if the
window is moved by the user. A window clips to the edge of the
display, whether or not there is another adjacent display.
Also, since the menu bar appears on all screens, Apple changed the way windows are constrained to screens. Also, from the 10.9 AppKit release notes:
constrainFrameRect:toScreen: now invoked for borderless windows
Prior
to 10.9, the NSWindow method -[NSWindow constraintFrameRect:toScreen:]
was invoked only for windows with NSTitledWindowMask set in their
styleMask. In 10.9, this method is invoked for all windows. The
default implementation does a more limited constraining for non-titled
windows, as described in “NSWindows constrained to not intersect the
menu bar” below.
NSWindows constrained to not intersect the menu bar
In 10.9, in
support of the new multi-monitor architecture, windows are now
constrained to not intersect the menu bar on their containing space.
This restriction was already in place for titled windows, but it has
been extended to borderless windows whose level is at least
NSNormalWindowLevel but less than NSMainMenuWindowLevel. This behavior
is implemented in -[NSWindow constraintFrameRect:toScreen:]. You may
override that method in an NSWindow subclass to adjust or prevent this
constraining.
So, you either have to use a custom subclass of NSWindow which overrides -constrainFrameRect:toScreen: to return the unconstrained frame, or you have to set your window's level to NSMainMenuWindowLevel or higher.

Creating semi-transparent, round cornered with border Window in Cocoa?

What would be the best approach for creating a Window that is semi-transparent, has round corners and an outline around its border and the arrow, but without the the title bar and buttons.
The window will pop up from the Menu Bar when a use clicks on the menu bar icon.
I'm looking to have an effect similar to the "Applications" and "Downloads" windows:
I guess I will need to do the drawing myself. But I'm wondering what's the best way to do this and whether there is anything already built into Cocoa that can minimize the effort? Or maybe a 3rd party project that has already done that (couldn't find anything exactly like that)?
Thanks.
You can create your window with
- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
with a style-mask of NSBorderlessWindowMask which will give an unadorned window. Its how the Dock does its mechanics too.
Note that you must init with this style , you can't change an already init'ed windows style.
Place a custom NSView via the contentView accessor with your desired background custom drawing at the top of the windows view stack.
You might need also to setOpaque to NO
What you are looking for has been done a lot. Too much really.
The classes you want to look into are as follows.
NSStatusItem
This is something that appears in the status bar section of the menu bar to the right side.
NSMenu
If you want this from a menu in the application menus, you'll need to do some clever things with views in menus.
NSWindow
As the other poster notes a borderless window is one way to achieve this.
NSPopover
This is another way. Combined with the above, a fancy technique is to use a clear window called a cover window then, when clicking on the menu or status menu, invoke a popover from a point below that in the clear cover window.
That should be enough to get you started with what you should look into.
Beyond that, peruse the Mac App Store and also look at cocoacontrols.com and GitHub.

Objective-C Lion Fullscreen use all monitors

We have 4 monitors on a wall for graphing. Looking to put them all into use in fullscreen mode. Right now if I do it it just uses one. Just looking to see if it is possible to create an app that allows me to use all 4 with like a simple uiwebview for each monitor.
Should of mentioned this.. Looking for a simple code sample of how to do this or pointers on where to get answers.
Yes, it is possible.
Standard Lion fullscreen mode allows for one "primary window", which is sized to take up the entire main screen, and as many "auxiliary windows" (inspector panels, etc.) as you want, which are not automatically sized in any way.
Go into Xcode, create a simple project, and edit the xib. For the existing window, go to the Attributes Inspector and make sure that Full Screen is set to "Primary Window". Now in the object browser, drag three Panels into the app. Go through them and make sure each one has "Utility Panel" for Style, "Auxiliary Window" for Full Screen, and either "Inferred Behavior" or "Transient Behavior" for Exposé. Now, when the first window goes into full screen mode (e.g., when you get the appropriate notification or NSWindowDelegate method), size and move the other three windows to take over the other three screens.
This is all documented pretty well in the Implementing the Full-Screen Experience section of the "Mac App Programming Guide" in the 10.7 Core Library.
If you're just looking to put a web view on each screen, it may be easier to use -[NSView enterFullScreenMode:withOptions:]. This isn't Lion's new full-screen mode, it's the earlier technique. It has different behavior in terms of whether the app is in a separate space, etc.

Making a full screen Cocoa app

I want to create a full Screen Cocoa application, however my app is slightly different from a conventional fullscreen app.
This app would be below everything else, so underneath the menu bar and the Dock, etc. It would have a large image covering up the Desktop and icons, with a custom NSView in the middle with a table view, etc. If this concept is hard to understand then here is an image:
http://img10.imageshack.us/img10/6308/mockupo.png
The only part that might be a bit confusing is the background image. This background image is NOT the wallpaper of the computer, but part of the app. So when the app is launched, it goes into full screen mode and puts itself underneath the dock and the menu bar, and underneath all other windows too. So it draws the background image to cover the screen (including Desktop and icons). Then has a custom NSView in the middle containing my controls.
What's the best way to go about doing this?
Thanks
Make a borderless window, the size of the menu-bar screen (screen 0—not [NSScreen mainScreen]), positioned at 0,0, with window level kCGDesktopWindowLevel.
Remember that you will need to observe for screen frame-change notifications (when the user changes the screen dimensions), and that you should correctly handle the case of no screen at all (headless Mac).
I think #Peter Hosey’s solution should work, but to make other windows go on top, you will probably need to change the window level to something else.
But, I implore you, do not do this. This will be the most bugly application the Macintosh has ever seen. There are a lot of really good user interface paradigms that you can use, and "replicating" the main desktop interface of Mac OS X is generally not one of them. That is, unless you are reimplementing Time Machine or something like that.

How to create a Controller to simulate the Springboard feature of the iPhone within your own application

I am trying to design a feature in my application for the iPhone that simulates the Springboard feature (Main menu of the iPhone that allows you to view more apps), or the way Weather application works that allows you to flip between views.
Does anyone have any samples of this how I would go about doing this. It's seems very trivial but I am wondering if I am missing something that is already available either as an Apple example or someone who did a tutorial on this.
The image below show how the user would use it.
alt text http://www.agilitesoftware.com/SpringboardExample.png
As they slide their finger to the right (or left) the other image would begin to show up. And it would animate smoothly. The faster you swiped your finger the faster it would move to the next view.
Update: The other feature is that it should mimic the same feel when you slide your hand across the display that is snaps to the current view into place. It should not keep sliding across if there is more than 1 view to the direction you swiping your finger.
I've seen other applications use this so that is why I am asking.
This is accomplished using the UIScrollView with the pagingEnabled property set to true. Just add each of your views, adjust the contentSize, and it will automatically "page" to the width of the screen across the content.
There is a sample app (with code) with exactly this functionality on the iPhone developer site on Apple.com (I believe it's called "PageControl".) - I'd suggest checking it out.
d.
I'm writing an app that uses a similar UI. As NilObject recommended, we're using a UIScrollView with pagingEnabled=YES.
You may also be interested in this example code involving just two child views. I'm trying it out now; it's an interesting technique but I've had to write some additional special-casing code for some odd situations that resulted.
There's also another question on this site that asks about creating a grid of icons like the home screen.
I would check out Joe Hewitt's code from the Three20 project for this. It provides a nice interface and further refinement of the UIScrollView implemented as TTScrollView and TTScrollViewDelegate, TTScrollViewDataSource.