NSView Absorb Clicks? - objective-c

I have my standard app setup, window with lots of views. From time to time I place an NSView over the top of everything, black with some transparency, to act an a dimmer/overlay.
I need this top overlay view to absorb all clicks so that any views underneath it can't be interacted with. E.g. an NSButton under this NSView won't be clickable.
How can I do this?
I have seen -(NSView *)hitTest:(NSPoint)aPoint but I don't want to put this on every single subview with a rule to block clicks while the overlay view is present.

Override the NSView with an empty mouseDown: and the views underneath will not receive any mouse events.

Related

UIButton steals UIView touch events

I have a class which subclassed UIView. The class only have touch methods (to rotate view according to users touch).
From storyboard i added a view to my ViewController's view and subclassed it with that custom class. The idea behind to receive its touch events, thats it.
In that View some UIButton is place covering the whole view.
Now requirement is when user clicks on button then its action should call else if he tries to rotate the view it should give spin rotation.
Every thing is working fine if i make user interaction of button to be false as obviously now Uiview is the responder. But this not what i want. I want button to be interact to action as usual and if user move his figure then rotate the view.
I achieve same thing with UIRotationGestureRecognizer but it is meant with 2 figures touch and i need to achieve same thing with single finger touch.
Any help and suggestions will be appreciated.

How do automatically resize an NSPopover with auto layout

I currently have an NSPopover subclass which sets it content view controller to a custom NSViewController meant to represent a tab view:
self.popover.contentViewController = tabViewController;
self.popover.animates = YES;
I'm rolling my own "tab view controller" because I've heard that NSTabViewController doesn't play well with animations. I'd like to use auto layout so I don't think I want to mess around with the popover's contentSize property. When I change tabs the popover correctly changes its size, however, it doesn't animate the change. Furthermore, I have a cross-fade animation that occurs when the tab view switches and the popover doesn't resize until after the animation finishes.
First, I'd like to figure out how to get the popover resize to animate and then I'll worry about getting the animation in sync.
Thanks

NSTextView does not scroll when created with NSCollectionView

I have an NSTextView that is on a view that is the view of an NSCollectionViewItem. I give the user the option to hide the NSTextView and instead bring up an NSView object in its place on the same view.
However, when I run the program with the NSView object hidden and overlapping the NSTextView, scrolling in the NSTextView does not work correctly; The vertical scroll bar is there and adjusts its size accordingly to the size of the content in the NSTextView. However, the actual scrolling only works by highlighting the NSTextView's content and dragging upwards or downwards. What's more is that if I recreate the view without it being connected to an NSCollectionViewItem and NSCollectionView, it scrolls fine. This is an issue that happens not just with the custom view I have overlapping the NSTextView, but with any view object (buttons, image wells, etc) that overlaps an NSTextView, even if the view object is set as hidden.
Why is scrolling only possible when highlighting and dragging upwards or downwards if the NSTextView is being created with NSCollectionView and there is a view object overlapping it?
Well, I have found a solution that makes little sense but seems to work fine. I subclassed NSTextView and overrode mouseEntered with this:
-(void) mouseEntered:(NSEvent *)theEvent {
NSScrollView *scrollView=(NSScrollView*)self.superview.superview;
NSScroller *scroller=scrollView.verticalScroller;
[scrollView setVerticalScroller:nil];
[scrollView setVerticalScroller:scroller];
}
If anyone has any idea as to why this issue is happening or a better solution and not just a guess-around, please post it

scrollview, buttons events exchange

I have a scrollview where I added several buttons (dynamically, programmatically). Hence my view is totally covered with buttons. Also there are some labels
However, I observed that the uiscrollview is not scrolling when the drag starts on the button. All labels work fine. But I want this scroll to happen i.e. when drag event occurs in the uibutton, I want it to send this event to its superview (scrollview).
Please note, according to my search, subclassing the scrollview and overrriding the content touches event, or add touch began actions to uibuttons are not helpful.
How do one in general work with this event passing things when objects are added dynamically?
You have to subclass the UIScrollView, there's no other proper way, but you do not need to mess with the touch events. All you have to do is override this method
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
return YES;
}
And set the canCancelContentTouches property of the UIScrollView to YES.

Handle tap event by subview of UIScrollView while scrolling

I have custom UIScrollView subclass with some content views inside. In some of them I have UITapGestureRecogniser. All works fine when scroll view is not scrolling. But when it scrolling content views does not receive tap action. What is the simplest solution to handle tap action by subview while scroll view is scrolling?
Details:
MyScrollView scrolls horizontally. It contains a lot of content views (e.g. MyContentView). Each MyContentView has width about one third of MyScrollView width. So there are about 3-4 visible MyContentView elements at a moment. The main behavior of MyScrollView is to 1)make sure that after scrolling one of MyContentView elements will be at center of screen and 2)to scroll to center of MyContentView if user taps on it. So the main answer I hope to get is how to "properly" implement handling of tap action in MyContentView while MyScrollView is decelerating.
I found some same questions and answers but none of them satisfied me. The best was to implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: of UITapGestureRecogniser delegate. But in this case I sometimes (when I tap, make smaaaal drag and release finger so tap is steel recognizable(lets called it quasi tap)) have both tap and scroll events and it leads to bugs for me even if scroll view is not scrolling when I begin tap. When user make quasi tap my application tries to scroll to tapped MyContentView element and than immediately handle normal scrolling. It seems even more terrible, due to some other functionality start to perform after handling tap (it must not perform when normal scrolling).
I need solution where scroll view wait enough to decide it is not tap event and only then make scroll. Otherwise if tap event had recognized scroll must not happen.
You can go with the custom delegates methods as well, using #protocol. Implement those delegate methods in view controller where your UIScrollView has been added.
like in MyContentView:
In touchesBegan method,
[self.delegate contentViewTapped:self];
Now in ContainerView class where scroll view is added, implement that method:
- (void)contentViewTapped:(MyContentView *)myContentView {
NSLog (#"ContentView no: %d", myContentView.tag); // if tag has been set while adding this view to scrollview.
}
Go through the examples for #protocol.
Hope this is what you required.
Enjoy Coding :)
This is built into UIScrollView - take a look at the delaysContentTouches and canCancelContentTouches properties. This should alleviate the problem when dragging a small bit after a tap.
This is all system built-in behaviour. I would suggest sticking with what Apple has provided for the feel of your interface (how it reacts to small drags, for instance) so that your app doesn't feel out of place on a user's phone.
EDIT:
Alternatively, you could disable scrolling of your scroll view in you gesture recognizer and re-enable it once it's ended/cancelled.
Further Edit:
I don't understand - I've created a sample project that illustrates how to intercept touches in a subview of a scroll view using gesture recognizer delegate methods. Play close attention to the "Cancellable Content Touches" and "Delays Content Touches" properties of the scroll view. They're both YES for very important reasons.
You scroll view should be delaying content touches until it has determined if the user is attempting a tap, pseudo-tap (as you put it), or a pan for the scroll view. Apple has already written the functionality you're trying to build; UIScrollView will already do what you want.
The problem is that the system doesn't want a scroll view's subviews intercepting tap events while the scroll view is scrolling. To this end, it cancels touch events if it determines that the user is actually trying to pan. Setting "Delays Content Touches" enables this behaviour. Ensure it's turned on and you should be fine.