I have an image that can be dragged on the screen along the y axis and it works brilliantly, but when when I place a button on top of the image which tracks the image (moves with the image, so it's always on top), when trying to drag the button (as it's on top of the image I want to drag), the image won't budge. The button is just cancelling out the drag gesture. How do I prevent this from happening while still enabling the user to press the button? I'm using a UIPanGestureRecognizer
I've tried various ways but they don't work. Go steady with me please, I've very new to developing and this is my first App Store app :)
Thanks
I am not sure if these will solve your issue but you can try both of them and see which one works.
1) Make the UIButton a subview of the UIImage so that it inherits the gesture recognizer.
2) Add a pan gesture recognizer to the UIButton with the same handler as the image.
Related
I'm stuck with a problem with pinch gesture. So I have a pinch gesture on an UIImageView which is itself in a collectionView, and when the user starts zooming, I add new, separates ViewController to control the zoom and pan gestures on the image, so I add my UIImageView to the new ViewController's view. The problem is, when I change my UIImageView hierarchy, the pinch gesture attached to it stops working, so the user has to take off his fingers and start pinch again in order to zoom the image. So basically, I am searching solutions to one off these:
1. Make pinch gesture work right when changing gesture.view hierarchy
OR
2. Make pinch gesture work right when changing gesture.view. So another way is to add a new view to the new ViewController and attach gesture to that view. But it still resets the gesture touches and you need to start it again.
If anyone has any suggestions, please help. Thanks a lot.
Ok, I found the answer. You just need to set userinteraction of vc's view to NO. Works like a charm.
- The functionality which is required by client is already implemented using UISwipeGestureRecognizer but I am not able to give animation which is needed.
- I want the animation of dragging image as its in paging effect of UIScrollview.
Let me explain in detail:
- In UIScrollView with paging enabled, when we drag image, it will be dragged behind our finger not just slight swipe.
- In my case its moving away as soon as the finger moves over the image, so I want the animation of image to be sliding as far as my fingers moves and on leaving it should move away.
-Friends, I don't want curl effect but I only want swipping functionality as far as my finger moves.
I think you can take a look at this repository and you can find what you need if you edit this repository code and use PanGestureRecognizer instead of SwipeGestureRecognizer in this repository.
https://github.com/agrawalmahesh/MKImageSlideshow
You need to disable paging property of the UIScrollView.
How can I make the area of a UIButton in which the button still triggers the touchUpInside method smaller? When I press a button and drag my finger outside it (not lifting the finger), the area outside the button's bounds that keeps the button highlighted is pretty large.
I would like to achieve that the touchUpInside method would only get triggered if the finger (being dragged) is still inside the bounds of the button. Currently, if you press a button and, while not lifting your finger, you drag your finger outside the button, the area in which the touchUpInside method (instead of the touchUpOutside method) is called is pretty big. Can I limit the touchUpInside method to get called only if the finger is inside the bounds of the button?
Thank you.
I'm not pretty sure if I clearly understand your problem. So I would like to provide my 2 solutions:
The tricky one: you add another smaller subview to the button which being dragged, you turn off userInteraction of this button and reactivate it when you're done dragging.
Disable userInteraction for the stable button, you recognise if the two buttons touch each others base on their frame. Reactive userInteraction when you're done just like above.
Does anyone know how I can replicate the iPhone Path App functionality when you click on an image from the news feed view. Once clicked, the image grows (animated) to a full-screen view where you can pinch in and out to zoom. A single tap reverses the animation and goes back to the news feed view. It's a pretty neat implementation that I'd like to include in my app.
My initial guess is that the news feed contains a disabled UIScrollView and then the frame of the UIScrollView gets animated to the entire frame upon a tap.
One way to do it, is just have many UIButtons (with Custom image) as the thumbnails. And then assign IBAction to detect which image(button) is tapped. In this IBAction, animate the enlargement of the UIButton and at the end of animation, create programatically a UIScrollView and UIImageView. Insert the UIImageView into the UIScrollView. At this point you'd be able to pinch zoom and pan around the image. Then detect a touch and upon touch, remove and release the UISCrollView and UIImageView and animate back the UIButton to its original location and size.
I'm trying to come up with a UISCrollView in paging mode, where each page shows an image of a product and, besides being able to swipe between pages, I'd also like for the product image to switch to a "down" version of it when a specific product/page is tapped.
So far I tried the following:
1 - adding UIButtons as the pages of the scrollview: obviously, this way I can have the images switch to their "Selected" version on finger down, but the buttons, taking up the whole page, prevent the scrollview from detecting the swipe gesture.
2 - adding UIVIews instead of buttons, and an UITapGestureRecognizer: this way I can tap an image to select a product and the recognizer also lets the gesture pass on to the scrollview, allowing for swiping too. But the problem with this approach is that I can't switch images to their "selected" versions when the user touches them, since the tap recognizer only reports UIGestureRecognizerStateEnded.
Any ideas as to how to get both the button up/down and scrollview swipe behaviors?
Scrap everything (well not everything, but you get the gist). No gesture recognizers no nothing. I recently had this problem too, having mounted a UIView on a UIScrollview that needed to have some interactive elements in it. The solution, UIView's friggin awesome property called exclusiveTouch. Exclusive touch takes all of the events from the scrollview, and ignores them if the event is inside the UIView, then passes them directly to your view. And because UIButton inherits from UIView, all you need is self.button.exclusiveTouch = YES
Pretty cool, huh!?