How to ignore mouse moves over hidden part of NSView? - objective-c

I have some window which in turn contains an NSView, v1. The view can receive events from mouse, like Mouse Down, Enter, Exit and so on. The view can be overlapped by other view (v2) (modal window not involved).
I want to be able receive events Enter/Exit in v1 when the mouse is over visible part of v1, and ignore those events when the mouse is over hidden region.
How? Enlighten me, please.

Eventually in my case solution was pretty simple: options for NSTrackingArea should include NSTrackingInVisibleRect

Related

NSView regisstering events on first click of mouse (making the app active)

I'm kind of pulling my hair out here. I have a single window application with a NSscrollView and custom NSViews inside of the scroll view. The custom NSViews are registering mouseUP and mouseDown events but my problem is that when the app/window is inactive and you click on it anywhere to make it active the mouseUP and mouseDown events are being triggered in the NSView that you click on.
I overrode the '(BOOL)acceptsFirstMouse:(NSEvent *)theEvent' to return NO just to be sure (i know this is the default.
I can't figure out what I'm doing wrong. I'm principally an iOS developer so my OS X experience is not super extensive. Any input helps. Thanks!
Found the issue. I had a NSTexField on the subview that was capturing the first mouseDown event. Just overlooked it.

UIButton events. What's the difference?

I've encountered a problem where my button should remain "pressed down" while it shows popover called from it. Popover is selector for some filter and filter is shown on button itself. When I tap on it and it shows popover it becomes deselected no matter what.
I think I have to redefine it's behavior on touch event and make it respond not to standart touch up inside. Then I wondered what are other events responsible for? But I couldn't find events list in iOS library and in StackOverflow are only questions about incorrect behavior of touch up inside or touch down.
So what's the difference betweeen touch events?
touch cancel - when you touch button but move your finger away and
it remains deselected?
touch down - right on tap.
touch down repeat ??
touch drag enter ??
touch drag exit ??
touch drag inside ??
touch drag outside ??
touch up inside - when you tap and release button remaining in it's
bounds . It changes UIButtons state to Normal.
touch up outside - when you tap and release button leaving it's
bounds ?
other IBActions are not sent by UIButton, right?
Also how those events change UIButton's appearance? Like highlighted or selected?
I'd appreciate a link on good article about IBActions, because I couldn't find it.
From Apple's doc for UIControlEvents:
UIControlEventTouchCancel
A system event canceling the current touches for the control.
UIControlEventTouchDown
A touch-down event in the control.
UIControlEventTouchDownRepeat
A repeated touch-down event in the control; for this event the value of the UITouch tapCount method is greater than one.
UIControlEventTouchDragEnter
An event where a finger is dragged into the bounds of the control.
UIControlEventTouchDragExit
An event where a finger is dragged from within a control to outside its bounds.
UIControlEventTouchDragInside
An event where a finger is dragged inside the bounds of the control.
UIControlEventTouchDragOutside
An event where a finger is dragged just outside the bounds of the control.
UIControlEventTouchUpInside
A touch-up event in the control where the finger is inside the bounds of the control.
UIControlEventTouchUpOutside
A touch-up event in the control where the finger is outside the bounds of the control.
Listed in, what I would consider, order of common use/likelihood of occurrence for a normal button:
UIControlEventTouchDown: The user tapped the button. This fires on the finger/stylus making contact.
UIControlEventTouchUpInside: The user tapped the button. This fires on the finger/stylus contact pulled back away from the screen.
Useful for sliders and drag events like moving a component around. The below are in order of occurrence:
UIControlEventTouchDragInside: Triggered as the finger drags into the button area.
UIControlEventTouchDragExit: Triggered during a drag motion. It is called only once, as the users finger/stylus leaves the bounds of the button.
UIControlEventTouchDragOutside: Triggered during a drag motion, after 'UIControlEventTouchDragExit', and is called continuously, as long as the original touch continues.
UIControlEventTouchUpOutside: This is simply the finger/stylus being lifted BUT only if the finger/stylus is no longer within the bounds of the button. The important thing (and probably obviously) to call out is that the touch had to have been within the button at some point to associate this event with the button.
Note: My understanding is that the above can be helpful for:
Sliders: as you might expect the touch may have been intentional but because of the quick swipe action, their finger movement may be sloppy and lift up outside of the slider area.
Moving components around, as when you push things around a screen you want the movement to happen when the finger/stylus touches the border of the component/object.
Other events:
UIControlEventTouchCancel: Something out of the user's control is cancelling their touch action. Think of this as something "going wrong" on the phone side of things.
UIControlEventTouchDownRepeat: Want to detect when your user is mad and tapping a button furiously? Want to detect if they're still in Windows mode and are trying to "double click"? Or maybe you designed a button to do something different if they tap twice. This event helps with all of those!
References:
SO 1: Dif between UIControlEventTouchDragOutside and UIControlEventTouchDragExit
SO 2: What is UIControlEventTouchCancel?

ios simulator: simulate swipe and drag

I have a UIView within a UIScrollView. When i want to simulate the drag event on the UIView, swipe event on the UIScrollView is being triggered.
As per the documentation , there isn't much of a difference between swipe and drag.
Swipe
1- Place the pointer at the start position.
2- Hold the mouse button.
3- Move the pointer in the swipe direction and release the mouse button.
Drag
1- Place the pointer at the start position.
2- Hold down the mouse button.
3- Move the pointer in the drag direction.
On an ipad I can use two fingers two swipe and one finger to drag. Now, how do i go about doing something similar on the simulator; drag instead of a swipe?
Edit 1:
I should have been clearer first up. Anyway, my problem is that the mouse drag is firing the swipe instead of drag, thereby scrolling the scroll view instead of passing on the drag event to the UIView contained by the scroll view.
I am on macbook pro. Two-finger swipe on the touchpad is being ignored. Touch and drag is causing the same thing as mouse-drag.
Thanks
See Jeff LaMarche's quick note on how to do this. It's documented in the same page you're reading, but Jeff's explanation is clearer.
If you want to simulate a two-finger gesture in the iPhone simulator, hold down the option key. You will get two dots on the screen instead of one. The two dots will default to pinching - if you bring the dot closer to the center of the screen, the other dot comes toward the center, making it easy to simulate a pinch in or pinch out.
If you want to do a different two-finger gesture, get the two dots the distance apart that you want them to be, then hold down the shift key, while still holding down the option key. That will lock the position of the two finger presses together so you can do, for example, a two-finger swipe.
see this documentation below:
iOS Simulator User Guide
Just use the mouse to drag the view, aka, left click the view then move the mouse
I ended up disabling the scrolling from the UI and added two buttons to scroll the scroll view. Since this is a work around only for the emulator, I have used #ifndef to hide the buttons while building for the device.

cocoa mousedown on a window and mouse up in another

I am developping a Cocoa application and I have a special need. In my main window, when I mouse down on a certain area, a new window (like a complex tooltip) appears. I want to be able to do:
- mouse down on the main window (mouse button stay pressed)
- user moves the mouse on the "tooltip" window and mouseup on it.
My issue is that the tooltip window does nto get any mousevent until the mouseup.
How can I fix this?
Thanks in advance for your help,
Regards,
And it won't since mouse is tracked by the main window. However, you can process mouseUp in the main window, transform click coordinates into the desktop space, get tooltip window frame and check whether the click occurred on the tooltip. After that, you can send a message to the tooltip window manually.
Or you can try to find another way to implement the final goal :) It is usually better to follow the rules, in this case - mouse tracking.

Mouse events for an NSSegmentedCell subclass?

I'm trying to implement some rudimentary tabs in a Cocoa editor I'm working on. I am using an NSSegmentedControl and adding segments to it as tabs. I'm using a custom NSSegmentedCell subclass for the tabs to draw a little 'x' icon next to the text for closing tabs and so far it's been going pretty smooth.
However, I cannot figure out how to actually process mouse events for the tabs to check if someone moused over (or clicked) the 'x' icon. I tried overriding "mouseMoved" in my NSSegmentedControl subclass, but for some odd reason it stops getting called when I add a new segment to it (I set "setAcceptsMouseMovedEvents" to yes in awakeFromNib, do I have to also set it somewhere else??). NSSegmentedCells, being NSCell subclasses seem to not have any mouse event processing, aside from mouse tracking, which gets triggered only when the control is clicked.
So the question is, how would I properly process mouse events, either in the NSSegmentedControl or in the NSSegmentedCell subclass?
Take a look at NSTrackingArea. You can add a tracking area to your NSSegmentedControl and get mouse-entered events on that to highlight the close button.
As for getting the click events, you're probably best off using a separate NSActionCell subclass for the close button and do some hit testing there.