Animation like Paging effect on UISwipeGestureRecognizer - ios

- 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.

Related

Objective C change pinch gesture view

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.

Using UIPanGestureRecognizer to slide to a new view controller

Im trying to add a welcome screen to my app that you "slide to unlock". The idea is very simple to the Potluck app. Essentially the user would slide the view and as they slide they will see the next view underneath the view they are sliding. When they slide past a certain point it goes to the next view. I'm trying to do this with UIPanGestureRecognizer. I'm assuming I need to find how far the user has dragged out the screen, which I'm not sure how to do. Thanks.
I found the effect Im trying to achieve online in a gif:
https://d262ilb51hltx0.cloudfront.net/max/800/1*tKuXa5qf4aSwuSnv05uqxQ.gif
You could use UIDynamicAnimator and UIDynamicBehaviors in order to get a realistic result. Although they're only available for iOS 7.
Set up UIGravityBehavior to pull the view towards the right direction.
Then create a UICollisionBehavior to stop the top view falling off the screen.
When the pan gesture starts, remove the gravity and attach a UIAttachmentBehavior to the center of the top view. As the pan moves, move the attachment to drag the top view. When the pan gesture is released use the UIPanGestureRecognizer to get the velocity in the view. Give the view a push in the direction of that velocity using UIPushBehavior. Then reapply the gravity in the appropriate direction.
Hope that helps!

how to stop a button from overruling a drag gesture

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.

UIScrollview, Move down responder chain

I'll try and keep it simple.
I have a UIScrollview with around 10 images attached. I currently have it so that i can touch an image and drag it around on the scroll view.
I did this by creating the subclass UIImageview and implementing the touchesMoved etc. I can still scroll the view fine, but the problem comes when trying to drag an image too fast. It seems the program first checks if the view is being scrolled and then fires touchesMoved in the UIImage class.
Is there anyway I can switch this around so that the first check is if an image is touched, then if not pass the response onto the scrollview.
Any help would be great. Thanks.
The simplest way to do this would be use one finger to move an image, and two fingers to scroll the view.
If you're on iOS 5, this is super easy:
self.scrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
If you want to support older versions of iOS, you have to do a little more work:
for (UIGestureRecognizer *gesture in self.scrollView.gestureRecognizers){
if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]){
((UIPanGestureRecognizer *)gesture).minimumNumberOfTouches = 2;
}
}
If you want to use one-finger gestures for both, there are a few ways to do it. You could attach a UIPanGestureRecognizer to each image view. You might need to tell the scroll view's own UIPanGestureRecognizer to defer to the image view recognizers, using the requireGestureRecognizerToFail: message.
Another way would be to set the scroll view's UIPanGestureRecognizer's delegate to an object you create that implements the gestureRecognizer:shouldReceiveTouch: method. In that method, you can check whether the touch's view is one of your image views. If so, return NO to prevent the scroll view's pan gesture recognizer from activating.
Your question is a little confusing to me but I will assume that you have a UIScrollView with 10 UIImageViews inside it which you want to drag around.
My suggestion would be to use a gesture recognizer (UIPanGestureRecognizer) attached to every UIIImageView in order to implement the dragging behaviour. I find gesture recognizers to be a more solid approach on this kind of behavior.
If you don't know how to work with gesture recognizers, I can post a short code example to demonstrate how you can drag any type of UIView. Just ask in a comment and I will write it.

UIscrollView swipe gesture + UIButton finger down effect on iOS

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!?

Resources