您的位置:首页 > 移动开发 > IOS开发

iOS 手势识别 ——长按和轻扫(swipe)

2015-08-15 11:42 519 查看
#import "MJViewController.h"

@interface MJViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;

@end

@implementation MJViewController

- (void)viewDidLoad
{
[super viewDidLoad];

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeView)];

swipe.direction = UISwipeGestureRecognizerDirectionUp;

[self.redView addGestureRecognizer:swipe];
}

- (void)swipeView
{
NSLog(@"swipeView");
}

- (void)testLongPress
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] init];
[longPress addTarget:self action:@selector(longPressView)];

// 至少长按2秒
longPress.minimumPressDuration = 2;

// 在触发手势之前,50px范围内长按有效
longPress.allowableMovement = 50;

[self.redView addGestureRecognizer:longPress];
}

- (void)longPressView
{
NSLog(@"长按了红色的view");
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: