Hide NSView in StatusBar Application - xcode

I have a small NSView (HUD-Style) in my StatusBar-Application.
If I get it right this NSView does not have a superview.
My problem is that I only want to show this view under certain programmatic circumstances.
What is the best way to show or hide this view?

One way to do this is to show this view in a borderless transparent window (NSBorderlessWindowMask).

Related

Cocoa: How to properly hide other views below NSImageView?

I have a view with several subviews (NSButton, NSTextField, NSPopUpButton) and a NSImageView with a spinner icon which should be displayed on top of the other views while data is retrieved from the web.
To display the NSImageView on top I have set
imageViewSpinner.wantsLayer = true
imageViewSpinner.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
The problem is, that the focus borders and PopUpButtons are still accessible/shining through the NSImageView (see attached video).
To solve this, I could iterate over all the other subviews and set them to "isHidden" or "disabled" but I wonder, if there is a cleaner solution to this problem, for example defining the NSImageView as topmost layer without things getting through?
You could put all of the other views inside of one container view and hide that.
You can also use a tab-less tab view to programmatically switch between view sub-hierarchies. (That basically achieves the same thing. It's better when there are more than 2 views to manage.)

Auto expand an NSWindow to fit an NSToolbar using auto layout

I have an NSWindow with an NSToolbar that I present as a sheet. I want the NSWindow to resize to fit the NSToolbar (so the buttons don't get chopped.)
The toolbar is not user configurable, but its size will change due to localisation.
I'm trying to achieve this using auto layout.
Any pointers would be most welcome.
Thanks

If a NSView uses autolayout, do all of its subviews also need to use autolayout for positioning?

I have a view in a window, the position and size of the view are calculated with autolayout. The view has a subview, a draggable NSView subclass. It is really easy to make a NSView "draggable" by overriding -mouseDown: and -mouseDragged: and changing the frame of the view directly.
The view hierarchy is as follows,
What is the best way of making the subview draggable in this case?
For example,
Is it possible for the subview to not use autolayout, so that it can be positioned by changing the frame directly? i.e. the window positions the main view, but then autolayout does not layout the subview inside the main view. Or do all views in the hierarchy need to use autolayout?
When I have used autolayout before, I have used it to make "fixed" layout that respond to resizing. But dragging a view with a mouse does't seems like a natural use-case for autolayout.
Is it possible for the subview to not use autolayout, so that it can be positioned by changing the frame directly?
Yes. If you keep translatesAutoresizingMaskIntoConstraints turned on, it automatically creates constraints from the values of frame and autoresizingMask.
In fact, this means it will use Auto Layout, but you can work with frame just like with manual positioning.
The best way is to not avoid auto layout.
Making a view draggable is pretty easy with auto layout constraint IBOutlets and getting the mouse delta from NSEvent short circuit mouse tracking.

detect scroll in horizontally uitableviewCell

I have UiTableView containing some data, and I want to scroll the UiTableViewCells horizontally to the left or right to show some UiButtons that act some action relatif to the content of the cell.
How Can I do this?
I'm thinking in creating custom cell, and putting a scrollView in it, May this did the trick?
There is a tutorial for this at http://idevrecipes.com/2011/04/14/how-does-the-twitter-iphone-app-implement-side-swiping-on-a-table/ with sample code. He is using a UISwipeGestureRecognizer to trigger an animation that pushes the cell off the screen.
You could use a swipe gesture recognizer attached to your cell.
You can add a UIScrollView to the contentView of a UITableViewCell. If you want to scroll the content using buttons, simply overlay the UIScrollView with buttons and make them call the various scrolling methods of UIScrollView.
Nested UIScrollView (UITableView inherits from UIScrollView) are quite clever about detecting touch conflicts and resolving the users intended gesture.
https://github.com/JonasGessner/JGScrollableTableViewCell might be what you're looking for. It implements this using a UIScrollView inside the cell (just like the iOS 7 mail app).
(Yes the answer is a bit late, but it's never too late! :P)

How to write an own resize corner/handle for an NSWindow?

How can I write an own resize corner/handle for an NSWindow? I'm using a subclass of an NSWindow without the default resize corner, but I need it for my window.
The basic outline:
Create a view.
Put some "drag me" indicator appropriate to your window in the view.
Have the view's drag action method respond by resizing the window so that the corner in question is now located at the current mouse position.

Resources