UISwipeGestrureRecognizer not recogising swipe down - swift - xcode

All I have an UIImage in an UIView and I have added an UISwipeGestureRecogniser in both IB and in code. Code is like this :
EventImage.addGestureRecognizer(swipeRec)
EventImage.userInteractionEnabled = true
swipeRec.addTarget(self, action: "swipedView")
It will read a 'right' swipe fine, but I want to control a down swipe.
The UImage is in an View and the View is a part of a scrollview. So I have switched off DirectionLock and Bounces. So the UIView cannot be pushed down from the NAV BAR. And it still doesn't recognise a swipe down.
Any ideas ?
In IB I have created the recogniser by dragging an 'Swipe Gesture Recogniser' on to the image I want to be able to use the gesture.
Then if i select the 'Gesture in IB' I can set which way the gesture goes, and I select down like this :
Then I set an func in swift and it does not recogise down but when I change it to right i works fine.. I have checked the idea by using breakpoints and the breakpoint triggers on Right swipe (and left) but going down doesn't work.
I think it could be because I am in a scroll view.
I have added :
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
As I thought this may help.
Hope this is clearer.

A UISwipeGestureRecognizer can only recognise swipes in one direction.
That direction is set in the direction property of it.
If you want to swipe right or down then you will need two gesture recognisers. One for the right swipe and one for the down swipe.
recognizer.direction = UISwipeGestureRecognizerDirection.Down
Also, it help to read the documentation. All of this info is directly from there.

Related

How to animate the insert of a UIBarButtonItem

I have a simple app with a Tool Bar at the bottom. Depending upon the context of what the user is doing, I may want various buttons visible or not in the Tool Bar. So, in my code, I remove the weak modifier for the IBOutlet reference to those buttons, and I remove the non-visible buttons in viewDidLoad. Great.
Now, when the context changes, I add/remove buttons as desired using
toolBar.items?.removeAtIndex(0)
toolBar.items?.insert(playButton, atIndex: 0)
Great, works well. But for aesthetics, I would like to have the button removal/insert animated. Apparently the animated:YES argument from Objective-C days is gone. Do you know, does the API support animation of the button shuffling? Or, if not, how best to accomplish this?
Thanks!

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)]

How to use UIScrollView with ViewControllers from Storyboard

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.

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)

SwipeGesture on ImageView

I am working on an app (its actually a game) that needs to detect Swipe Gestures. When I do swipe on my image view, the image for the image view needs to be changed, but unfortunately it is not working as expected.
When I add the swipe gesture object to self.view, the desired action is performed whenever I swipe my finger to any location in the view, but I want this action to be performed only when I swipe my finger over the imageView.
On the other hand, when I try to add the swipe gesture to the image view, it doesn't respond to the gesture event.
Please reply if you have the solution to this problem!
Thanks in advance!
It sounds like your UIImageView has userInteractionEnabled set to NO. Try setting yourImageView.userInteractionEnabled = YES and adding your swipe gesture recognizer to the UIImageView.
I too faced the same issue..
The option 'User Interaction Enabled' under Attributes Inspector(available in Inspector window of Interface Builder) was unchecked,
Enabling it solved my problem.
done using storyboard...
Thanks

Resources