I have a WKWebView (loaded with Google) in my macOS app. On top of that, I have added a subview (Gray one, with a white box) as follows.
let controller = MyViewController()
self.addChildViewController(controller)
self.view.addSubview(controller.view)
Eventhough my new view is at the top, still I am able to click the links in the webview.
I have been overriding the mouseDown in my view and block the click. But, if I move the mouse over the links, it is changing to pointed hand mouse.
Is there any way to block the user interaction at my new view itself, so that it does not pass through to the webview?
Thanks in advance.
Related
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.
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)]
I have a View Controller that is presented when you first open the app, and I have another controller that can be shown on screen if you tap a button at the top of the screen. However, instead of doing it this way I was wondering if I can either drag the view down or tap the button and have an animation take care of that.
I have tried doing this with a PageView Controller, but this doesn't show the effect I wanted as it simply translates over to the next view and doesn't actually keep the initial view fixed in place while the second view slides over it.
Also, instead of a view controller would a view initially placed out of bounds in the main View Controller work? Thanks in advance!
You could use a side menu like MMDrawerController that has 4 type of animations for presenting the viewController.
Or you can create your custom UIView (not viewController) even using Interface Builder and animate that screen yourself. The animation can be started using UIScreenEdgePanGestureRecognizer.
How would I use a UIScroll view (much like the main iPhone screen) with the page control at the bottom, pass UIViewControllers?
I have three UIViewControllers,that I would like the user to swipe back and forth. However these are already created in a Storyboard. I want the entry point to be the middle viewController and have the user wipe left and right to get to the 1st and 3rd view controller.
Am I right to assume that swiping is built into scroll view's with paging enabled?
Thanks in advance
-PaulS.
I have a transparent web view which is a large rectangle. The webpage it loads has smaller rectangles that don't fill the whole web view. So in those spaces not occupied by divs, you can see through the web view to whatever window or app is behind. Although you can see through, you can't click through.
I need to be able to click through the web view in parts of it that don't have active content.
Any ideas?
One of my ideas was have a transparent nsview on top of the web view, intercepting mouse downs , getting the coordinate, then referencing that coordinate in the web view and seeing if there is active content there, and if so, passing the mouse down event to the web view, but if not, ignoring it/passing it behind. This makes sense to me, but i don't know how I would accomplish this...
You need to subclass WebView and implement the hitTest: method. In your method, you need to test to see if the mouse is in one of the "active" regions of your web view and if it is not, return the view's next responder as the view passing the hit test.
//assume activeRect is some rect in your view that you want to accept mouse clicks on
- (NSView*)hitTest:(NSPoint)aPoint
{
if(NSPointInRect([self convertPoint:aPoint fromView:nil], activeRect))
{
//if the mouse is in an active area then just perform the default operation
return [super hitTest:aPoint];
}
//otherwise return the next responder
return (NSView*)[self nextResponder];
}