Successful Swipe in UITextView?

Import #define kMinimumGestureLength 25 #define kMaximumVariance 5 @interface SwipeableTextView : UITextView { CGPoint gestureStartPoint; } @end @implementation SwipeableTextView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { super touchesBegan:touches withEvent:event; UITouch *touch =touches anyObject; gestureStartPoint = touch locationInView:self; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { super touchesMoved:touches withEvent:event; UITouch *touch = touches anyObject; CGPoint currentPosition = touch locationInView:self; CGFloat deltaX = fabsf(gestureStartPoint. X - currentPosition. X); CGFloat deltaY = fabsf(gestureStartPoint.

Y - currentPosition. Y); if (deltaX >= kMinimumGestureLength && deltaY.

Thanks - I will try this today at some point and let you know how it goes. – mootymoots Jan 13 '10 at 9:50 I'm afraid this didn't work. I've added it as a subclass, changed the class to my new subclass in Interface Builder, and also updated the class in my main view controller to the subclass, but no swipe is detected :-( – mootymoots Jan 14 '10 at 16:21.

An even better solution, I have found, is to simply pass touches back to the superview: @interface SwipeableTextView : UITextView { } @end @implementation SwipeableTextView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { super touchesBegan:touches withEvent:event; self. Superview touchesBegan:touches withEvent:event; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { super touchesMoved:touches withEvent:event; self. Superview touchesMoved:touches withEvent:event; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { super touchesEnded:touches withEvent:event; self.

Superview touchesEnded:touches withEvent:event; } @end.

Add a transparent UIView on top of the UITextView and use it to handle the swipe, and send the touchesBegan/Moved/Ended/Canceled: messages to the text view to preserve normal interaction.

Usually you implement the touch responding events in a UITableViewCell, which can recognize the swipe and do something. UITableViews inherit from UIScrollView which does not like having touch events overridden.

– Ross Jan 12 '10 at 14:25 1 Not really much, other than it does a lot of complex work with touch events and so when it doesn't get everything it can't figure out what is going on... sorry I can't add more detail, I just know from experience it doesn't work well. – Kendall Helmstetter Gelner Jan 12 '10 at 17:09.

I took Ross's code and added a few things that helped me. In particular, this code won't respond to the swipe until it stops. It also prevents a swipe from reversing direction partway through.

#import #define kMinimumGestureLength 25 #define kMaximumVariance 5 typedef enum swipeDirection { kSwipeNone, kSwipeLeft, kSwipeRight } tSwipeDirection; @interface SwipeableTextView : UITextView { CGPoint gestureStartPoint; tSwipeDirection swipeDirection; } @end @implementation SwipeableTextView - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { super touchesBegan:touches withEvent:event; swipeDirection = kSwipeNone; UITouch *touch =touches anyObject; gestureStartPoint = touch locationInView:self; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { super touchesMoved:touches withEvent:event; UITouch *touch = touches anyObject; CGPoint currentPosition = touch locationInView:self; CGFloat deltaX = fabsf(gestureStartPoint. X - currentPosition. X); CGFloat deltaY = fabsf(gestureStartPoint.

Y - currentPosition. Y); // Check if we already started a swipe in a particular direction // Don't let the user reverse once they get going if (deltaX >= kMinimumGestureLength && deltaY X) { swipeDirection = kSwipeRight; } else { swipeDirection = kSwipeLeft; } } } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (swipeDirection == kSwipeRight) { NSLog(@"Swipe right"); } else if (swipeDirection == kSwipeLeft) { NSLog(@"Swipe left"); } super touchesEnded:touches withEvent:event; } @end.

You could also use a two finger swipe. When I get home I can elaborate with some code but that was what I have used.

This is my code and the event attach to it is not firing. It works for taps just not for swipes. How do I do that?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions