Im building an app that needs to detect a swipe gesture, the detector needs to recognize a swipe in any direction (not only Up, Down, Left, Right), the swipe can be in any direction for example somewhere around up and left.
The app features a ball in the middle of the screen, when the user swipes(flings) in any direction the the ball should shoot in that direction, so if the user shoots to a corner the ball should go to the corner of the screen. I don't want to use Unity or any engine, can anyone help me with the code for swift (not swiftUI)? Thank you in advance!
Related
I have a simple SCNScene with an object placed in the center (for example, a cube). BEFORE the latest update to Swift 4, I enabled allowsCameraControl and the user could then rotate and manipulate (zoom in/out) the cube. Now, (Swift 4, iOS 11) with the exact same code, when the user manipulates the cube, SOMETIMES the direction you swipe your finger matches the direction the cube moves, while other times, the direction you move your finger causes the cube to move the opposite direction! It is NOT something that is always backwards or always correct, it can change as quickly as swiping one direction (correct cube movement), raising your finger, going back and trying to continue the same motion, but now the second swipe makes it rotate back the wrong way!
It almost seems like it's trying to use some specific point in the scene as a 'reference' of some kind. Like if that point is on the front of the object, a swipe left makes it move left. But if that point gets moved to the 'back' of the object, the next swipe left still moves the POINT left, but because it's in the 'back', moving left translates into the front of the object moving right. (with the same thing for up and down!)
I would like to add a view to my app where I basically have a rotating circle of 'cards' (rectangles with rounded corners and information in them) that the user can swipe through. To get the illusion of the cards being laid out in a wheel, they would obviously need to disappear off the screen at a slight angle.
I was just looking for some guidance as to how I would go about this. I thought I would start with a UIScrollView with the cards sliding off horizontally and then work on the angle later? They would also probably need to have some sort of animation that centres them in the view when they decelerate to a stop.
Is there any tutorials online for this sort of thing? I did some searching and I couldn't find anything.
Here is what I'm looking for:
Thanks.
UISwipeGestureRecognizer only works for four directions i.e. up, down, right and left. I need to implement the swipe gestures to corners as well, like upper right corner, upper left corner, lower left corner and lower right corner. Is there any other way to do this rather than using UISwipeGestureRecognizer ? Any help will be appreciated.
If you need a swipe gesture recognizer that supports diagonal directions as well I suggest you create a custom gesture recognizer. It isn't that hard. You can find examples on Github. One that I'm aware of is called KTOneFingerRotationGestureRecognizer. It supports rotation gestures using one finger. That's different from what you want but it is an illustration of how to create a custom gesture recognizer.
You might even find a diagonal swipe gesture recognizer that somebody has already written on Github.
Edit: A quick search on Github revealed a project called DMCrookedSwiper.
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!
In my app, i have to implement two UIswipegesturerecognizers (left and right) one after another without removing the finger from screen.
What i have right now is user needs to swipe left and then swipe to right with removing finger .
Is there any idea how i can achieve this without removing my finger.
Thanks,
Use the UIPanGestureRecognizer and track the .x value and do the math yourself to figure out if the finger has gone far enough left from the origin (store the origin as a variable) and then far enough right from the origin.
Additionally you could just use UITouchesMoved and get the .x value of the touch.