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
Related
I have a modal window, which is perfect for iOS 13's drag to dismiss gesture, because this way the user remains in the context, so I don't want to use full screen. The controller contains a UICollectionView which displays a month calendar, which is scrollable vertically.
The problem is, that when the user wants to scroll upwards in the collection view, the dismiss gesture is triggered instead. If I scroll down first, then can I only scroll up.
I've tried to disable the internal UIPanGestureRecognizer (it seems somehow there is no presentedView, so it didn't work), tried to set the UICollectionView's pan gesture recognizer delegate to prevent the system recognizer to fire (it turned out you can't do that), and tried to scroll the collection view on appearing a bit (ugly).
How can I elegantly convince the the modal presentation, that my scrollview isn't scrolled to the top?
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)]
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.
I have a UIImageView that needs to be able to be panned all over the view, pinched and rotated, but the imageView needs to change picture on a swipe movement as well. Any idea on how to accomplish this? I have added a UISwipeGestureRecognizer but that will change the picture on any swipe movement. Ideal would be for me to make the picture animate away and the new one on to the screen once the user drags it of the screen or when it's not visible on the screen for more than 50%. Thanks in advance.
This is exactly what a UIScrollView was made for. Simply add all your UIImageView's to the UIScrollView, position them in the right order, and set .paging = YES. Make sure you also set the correct contentSize, or the UIScrollView won't scroll at all!
Also, check out the delegate methods for how to configure the UIScrollView for zooming. You may need to put the UIImageView's in their own UIScrollView which will enable zooming for that specific UIImageView, but this depends on your needs.
Hope that Helps!
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)