How do I write code to handle event that are fired when the track ball in a black berry app is swiped left and right?
The navigationMovement method of the selected field is called when such an event occurs. You can override it an place your logic there. The first parameter helps you determine what kind of movement it is(left/right) :
dx - Magnitude of navigational motion:
negative for a move left and postive
for a move right.
Related
I am developing an application, which has a map as its core feature. On this map, users can draw and edit polygons, lines, and add points of interest (POIs). To edit a polygon, for instance, one should tap on it, and the application would enter an editing mode after that.
To accomplish this kind of behaviour, I have a transparent overlay view (UIView), that lays just above the map. This view can either ‘capture’ user’s gesture (i.e. tap, long press, etc), if it hits an area of screen, that contains a polygon, or pass it down to the map, if there is no polygon met at the point of the tap. This behaviour is achieved by overriding a UIView method point(inside:with:) (docs here). The pseudocode for the implementation goes like this:
override public func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
if containsPolygongs(at: point) {
return true
} else {
return false
}
}
However, I have an edge-case that got me stuck a bit. Additionally to previously described behaviour, I want to be able to move the map when I put my finger down at the polygon and start sliding my finger around. Or the same with pinch-to-zoom behaviour. So, basically, depending on the type of gesture, I want my point(inside:with:) to return either true (for Tap gesture), or false (for Pan/Pinch gesture). Or, speaking more generically, I want my view to be ‘physically present’ when I tap on a polygon, and ‘physically absent’ when the received gesture is anything but a tap.
P. S.: I am not sure that my idea with point method is 100% correct and is a single possible one way of accomplishing this behaviour. Maybe there is a way to capture all the gestures and dispatch them to the view that lays below. Any idea is great as long as it works. Thanks!
I've just started work on a new game in which the player will fire a projectile by swiping in the direction he needs it to go in. I know how to detect if a swipe is left, right, up, or down using gesture recognizer, but I need to know how to get the angle of the swipe so the projectile can be fired in whatever direction and at whatever angle the player desires.
Sounds like you want to use a UIPanGestureRecognizer instead. Unlike the swipe recognizer, it's called continuously but with different states, so you could do something as simple as just handling the start and end states.
Docs:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPanGestureRecognizer_Class/index.html
I'm starting with the SpriteKit, and actually i want to move my Hero in a game by a buttons on screen.
But i want the hero move as user stay pressing the button, if use take your finger off the button the Hero stop moving.
At first i think about use the touchesBegan(and End) with booleans, when user tap set the boolean true and star an action that moves Hero if bolean is true, and when user take off button set to false.
i think this method is pretty bad, further take into consideration use sprite animations ( actually i have no idea how ir works)
i know this question isn`t very good but i search for something like this and i have found nothing too specific. Thx
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 want to create a hidden part of my game that is triggered by doing a series of touches and swipes on the game over screen. Kind of like the old Nintendo style unlocks but with iPhones & iPads.
I want a pattern like this to unlock the secret level. Swipe down, swipe down, swipe up, swipe down, swipe right, swipe left, two finger long press. Is something like this possible and if so, how would I go about it? Thanks.
You can register several different gesture recognizers, and then, as they are triggered by the user's actions, track the sequence and if/when it matches your "secret" pattern, invoke the view controller for your hidden section.
To track the swipe/touch sequence (assuming the sequence is always the same), just have an instance variable which holds the next expected event. e.g. initially you are expecting a SWIPE-DOWN.
When you get an event, if it is the expected event, then advance to the next one e.g SWIPE-UP. If it is wrong, then reset the expected event to its initial state.
If you get all the events in the right order, then you unlock the hidden view.