Changing NSCollectionView dragging image while moving mouse around - macos

I use a NSCollectionView as a toolbox (like in Xcode's Interface Builder). When dragging a tool out of the collection view I would like to change the "dragging image" under the mouse cursor into the real tool image. It should behave similar to Interface Builder when dragging a UI item into the users canvas. Es expected, it should change back to the previous image when I move the mouse back into the collection view.
I tried several delegate methods, but I can't see a way to change the cursor image during mouse movement.
Any suggestions?
Thanks to all! :-)
Regards,
Ulf

make a subclass of nscollectionview
override
func beginDraggingSession(with items: [NSDraggingItem], event: NSEvent, source: NSDraggingSource) -> NSDraggingSession
use setDraggingFrame(_:contents:)
you can get the mouse point from event.locatoinInWindow (dont forget converting to your collectionview cordinate)

Related

Add an NSView around cursor?

Simple question, starting out with macOS stuff – I’d like to create a small radial menu around my cursor, top-most, above whatever application is currently active, whenever a specific mouse button is pressed.
I have the specific mouse button over all application down, but I’m wondering where I need to draw that NSView, i.e. “topmost”. I guess on iOS this would be at the UIWindow level, but would NSWindow be the wrong approach here?
this is purely an opinion-based question, but basically if you want to present any custom content on the desktop, that should use NSWindow, and you can customise the window's content for your wish.
NOTE: you can find more information about the NSWindow class in Apple's Class Reference Docs.

NSOutlineView selectionIsChanging on mouse up

I've got a Mac app involving an NSOutlineView. The view controller containing the outline view implements outlineViewSelectionIsChanging: to set selection state in a custom way on the cells in the outline view (it's view-based). But selectionIsChanging is called on mouse up, not mouse down. I've got other view controllers with other outline views in the app that get selectionIsChanging properly on mouse down, but I can't find a difference. Is this a property on NSOutlineView / NSTableView? Or is there another probable cause of this?
Turns out that if drag-and-drop is implemented on the outline view, it only posts selection messages on mouse up.

UIScrollView on tvOS

The question is very simple, how to enable scroll and zoom inside a UIScrollView in tvOS?
I tried the same initializer code from iOS and returned the scrollview for the focusedView var, but nothing happens when i touch the remote.
Also, i tried to add another custom UIPanGestureRecognizer to the scrollview and actually it works, but i don't want to handle the pan with custom code, just use the same pan behavior like iOS.
Let me know, thanks.
You can configure the scroll view's built-in pan gesture to recognize touches on the Siri Remote. It doesn't do that automatically, because normally scroll views on tvOS aren't scrolled directly by touches: they're scrolled automatically as focus moves between views within the scroll view.
If you really want the scroll view to move directly from touches, you'll need to add UITouchTypeIndirect to the allowedTouchTypes of the scroll view's panGestureRecognizer:
scrollView.panGestureRecognizer.allowedTouchTypes = #[ #(UITouchTypeIndirect) ];
You'll also need to make sure that either the scroll view itself is the focused view, or is a parent of the focused view, since all touches from the remote will start at the center of the focused view: you need to make sure the scroll view is getting hit-tested for the events to work.
Zooming won't work, because the Siri Remote can only recognize one touch at a time, so you can't do a pinch gesture on it.
Swift 4 version (from here: https://stackoverflow.com/a/41000183/945247)
scrollView.panGestureRecognizer.allowedTouchTypes = [NSNumber(value:UITouchType.indirect.rawValue)]

Highlight NSImageView in NSView

I have a simple question. I have my NSView which is detecting drops (drag and drop). When user drops a link with image from browser, I detect that action, create NSImageView, initialize it on a place where user dropped it with some default frameSize and put the image from the link into it.
I would now like to highlight that NSImageView when user clicks on it. I also want to implement moving around that NSImageView in NSView but I'm pretty sure I will manage that. How do I highlight that exact NSImageView which was clicked? I haven't created earlier that NSImageView in interfacebuilder and assigned a special class for it so I can use drawRect, I have just created it dynamically...
Any help would be appreciated.
You can use NSImageView's setImageFrameStyle for highlighting.

Creating NSToolbar style buttons

Is there a bevel style that can replicate NSToolbar style of buttons that are used, for instance, in the Safari's preferences window to switch between different panes?
I need to replicate NSToolbar in an NSView using NSButtons. I understand that I should probably be using NSTabView, but I'd like to implement the look of xcode's left pane. Any tips here would be appreciated greatly.
There's nothing built-in, you'd have to create the images yourself. However, replicating the behaviour is straightforward.
You could simply use a single-row NSMatrix of NSButton objects. Just give the buttons an image and an alternate image (for the highlighted state) and set the matrix mode to NSRadioModeMatrix.

Resources