I'm trying to make a card game app (with swift 4) like a Solitaire Card Game.
So I have to use Drag and Drop to each Card UIView.
But I think there are two ways to use for dragging.
Which one is better between UIPanGesture and UIDragInteraction/UIDropInteraction?
Furthermore, I'm not sure about what panning means.
2. what is difference between dragging and panning?
(From Apple site: UIDragInteraction & UIPanGestureRecognizer),
UIDragInteraction
An interaction to enable dragging of items from a view, employing a delegate to provide drag items and to respond to calls from the drag session.
UIPanGestureRecognizer
A concrete subclass of UIGestureRecognizer that looks for panning (dragging) gestures.
Here, Pan & Drag gesture is almost same.
Some of differences which I got from searching are as follow..
UIDragInteraction works from iOS 11.0+ & UIPanGestureRecognizer works from iOS 3.2+, so if you want to run your application in older version devices then you should use UIPanGestureRecognizer
UIPanGestureRecognizer works on the whole screen & gives you the CGPoints as response of touch where UIDragInteraction works on the particular object you want to drag & drop & gives you direct the view object.
UIPanGestureRecognizer can work with multiple touches & handle those where UIDragInteraction doesn't allow you to handle multiple touch.
Hope this helps.
Thanks
Related
In my iPad project i have to make
1.Tap gesture
2.Swipe right and Swipe left Gesture
3.Single Finger Pan Gesture
4.Two finger Pan gesture.
5.Long press gesture
I don't know how to handle all these gestures.When Long press gesture is used only Swipe right gesture and two finger Pan gesture has to work. App gets confused at these many gestures in a single screen. How to Handle everything easily. Please help
Firstly i will say your question was little confusing and we can easily add multiple UITapGestures on a singleView without any prob. The OS automatically detects which gestures you are doing. There are many tutorials for that. Look at these links, if you still can find any solution, tell me may be i can try a code piece for u.
Link 1
Link 2
and lastly
Link 3
I'm new to developing iOS apps,
I've successfully implemented a Swipe Gesture Recognizer,
What I was wondering is if there is an easy to use recognizer like the swipe gesture. That would let you implement the homescreen page turning effect but just on a small view in the view controller?
If your unclear on what effect I mean, when you look at the iPhone's homescreen you can drag your finger and it responds instantly (unlike swipe) and also has some spring feeling to it, is this some effect I can use, or do I manually have to program this into the code if so is there a tutorial that explains this?
Thanks,
I hope my question makes sense.
Have a look at UIPanGestureRecognizer:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIPanGestureRecognizer_Class/Reference/Reference.html
UIPanGestureRecognizer is a concrete subclass of UIGestureRecognizer
that looks for panning (dragging) gestures. The user must be pressing
one or more fingers on a view while they pan it. Clients implementing
the action method for this gesture recognizer can ask it for the
current translation and velocity of the gesture.
A panning gesture is continuous. It begins
(UIGestureRecognizerStateBegan) when the minimum number of fingers
allowed (minimumNumberOfTouches) has moved enough to be considered a
pan. It changes (UIGestureRecognizerStateChanged) when a finger moves
while at least the minimum number of fingers are pressed down. It ends
(UIGestureRecognizerStateEnded) when all fingers are lifted.
Clients of this class can, in their action methods, query the
UIPanGestureRecognizer object for the current translation of the
gesture (translationInView:) and the velocity of the translation
(velocityInView:). They can specify the view whose coordinate system
should be used for the translation and velocity values. Clients may
also reset the translation to a desired value.
Edit: The spring feeling part you would need to implement yourself. Since iOS 7 there is UIDynamics which contains different animators, for what you describe you may need UIGravityBehavior and maybe UICollisionBehaviour. Look at the WWDC 2013 videos for this topic, I think you will find some examples there.
I was trying show a bunch of images, one at once. User could swipe left or right to navigate, just like photo library.
What I did is, for example I have 6 images, create a scroll view to hold those 6 images, and using pan gesture to move it.
Am I doing right? Or is there another neat solution?
Thanks
EDIT:
I'm asking am I doing right by using gesture?
More specific, should I use UIScrollView to do this or I should use something else?
Update:
I finally figure out a way to do. Use UIPanGestureRecognizer and check the speed. if the speed is fast enough, then treat like swipe gesture. Will post code later.
UIScrollView has a default gesture and does not need a new one.
I know this has been probably asked before but I've seen many approaches and i don't know which is best for me, so plz don't send me a link to another post unless it addresses my problem directly.
I have a controller which has a uiview on the top (like a header) (this header is bigger than it seems because is partially hidden on top). on that view i have a uibutton which now with a touch up inside shows the entire header view and taping again returns it to its starting position (changing frame with animation). I want to also be able to drag the view but only changing position on the y axis(dragging up and down)... i was thinking of adding the dragInside/Outside event to the button but this doesn't give me the position of the finger... and also want to know when the user releases the drag so the view ends animation to any of its two possible states (showing or partially hidden). Is this a "touches began" , "touches moved" , "touches ended" thing? if it is please provide a code example. I also want to do this with another view but this is on the left side... same thing but this one moves on the X axis... any help is appreciated. or maybe it can be made with drag event if i only can save a CGpoint of last touch, maybe that's better, any other suggestions
Look at using a UIPanGestureRecognizer to detect the touch movements. Use the translationInView: of the gesture to set the view y position. The translation is the total movement since the start of the gesture so you don't need to remember and accumulate the offset position yourself.
The main thing to worry about while implementing this is bounding the y position of the view so that no matter how far the user drags the view won't go too high or low on the screen.
Use a UIPanGestureRecognizer, that's a class dedicated to handling such drag/pan gestures.
Everything is described here in Apple's documentation, including examples, so you should find your answer here.
There is also some sample code in Apple Developer Library that shows you how to use Gesture Recognizers if needed.
I have been developing collage like application. In which user can add images, they can scale, move and rotate them. Whenever, I am trying to drag an image which is on top but added earlier than the one behind it, it is not receiving the gesture, rather than the one behind it which is added later gets detected and brought into front. How to resolve this issue?
I am Using this to remove the gesture in second view...
[imageView1 removeGestureRecognizer:GestureInView2];
This are the delegate method of UIGestureRecognizer you can use for your different requirement.
touchesBegan:withEvent:
touchesMoved:withEvent:
touchesEnded:withEvent:
I didn't understand your issue perfectly, But.
I think you have to refer for more detail according to your requirement - https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html.
I have done it. We need to change the index of subviews if you want to make them receive touches. Changing zposition alone will not help to make the view to receive touches.