Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

iphone - Successful Swipe in UITextView?

Has anyone been able to implement a successful swipe gesture on a UITableView? By default this is not possible due to the scrolling nature of the control. I've tried subclassing UITextView and implementing the swipe function in the instance methods, but no dice.

My UITextView has scrolling disabled - Unless there is another way to implement multiline text?

[Edit] What I should say is input multiline text[/Edit]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is a subclass of a UITextView that will detect a swipes gesture...

Is this what you are looking for?

#import <UIKit/UIKit.h>

#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 <= kMaximumVariance) {
        NSLog(@"Horizontal swipe detected");
    }

}

@end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...