ios手势识别-长按+轻扫

//
//  MJViewController.m
//  08-长按+轻扫
//
//  Created by apple on 14-4-20.
//  Copyright (c) 2014年 itcast. All rights reserved.
//

#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

时间: 2024-08-25 19:03:09

ios手势识别-长按+轻扫的相关文章

手势识别(点按,长按,轻扫)

08-手势识别(点按,长按,轻扫) 通过touches方法监听view触摸事件有以下几个缺点     1.必须得自定义view,在自定义的View当中去实现touches方法.     2.由于是在view内部的touches方法中监听触摸事件,因此默认情况下,无法让其他外界对象监听view的触摸事件     3.不容易区分用户的具体手势行为(不容易区分是长按手势,还是缩放手势)这些等.          iOS 3.2之后,苹果推出了手势识别功能(Gesture Recognizer在触摸事件

iOS开发UI篇—手势识别器(长按+轻扫)

iOS开发UI篇—手势识别器(长按+轻扫) 一.长按事件 1 // 2 // YYViewController.m 3 // 03-长按 4 // 5 // Created by apple on 14-6-19. 6 // Copyright (c) 2014年 itcase. All rights reserved. 7 // 8 9 #import "YYViewController.h" 10 11 @interface YYViewController () 12 @prop

iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义

1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureRecognizer 的子类),开发者可以直接使用他们进行手势操作. UIPanGestureRecognizer(拖动) UIPinchGestureRecognizer(捏合) UIRotationGestureRecognizer(旋转) UITapGestureRecognizer(点按) UILo

IOS 手势学习(点击,长按,轻扫,拖拽,旋转,捏合缩放)

点击        UITapGestureRecognizer 长按        UILongPressGestureRecognizer 轻扫        UISwipeGestureRecognizer 拖拽        UIPanGestureRecognizer 旋转        UIRotationGestureRecognizer 捏合缩放 UIPinchGestureRecognizer 详细代码如下: #import "ViewController.h" @i

ios手势识别之轻扫

1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 5 // 向上 6 UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] init]; 7 // 设置轻扫的方向 8 swipe.direction = UISwipeGestureRecognizerDirectionUp; 9 [self.customView addGestureRecognizer:swip

iOS手势操作,拖动,轻击,捏合,旋转,长按,自定义(http://www.cnblogs.com/huangjianwu/p/4675648.html)

1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureRecognizer 的子类),开发者可以直接使用他们进行手势操作. UIPanGestureRecognizer(拖动) UIPinchGestureRecognizer(捏合) UIRotationGestureRecognizer(旋转) UITapGestureRecognizer(点按) UILo

iOS七大手势之(平移、捏合、轻扫、屏幕边缘轻扫)手势识别器方法

使用手势很简单,分为两步: 创建手势实例.当创建手势时,指定一个回调方法,当手势开始,改变.或结束时,回调方法被调用. 添加到需要识别的View中.每个手势只对应一个View,当屏幕触摸在View的边界内时,如果手势和预定的一样,那就会回调方法. (四).平移手势 (五).捏合手势 (六).轻扫手势 通过轻扫手势来改变视图上的图片 (七).屏幕边缘轻扫手势 通过屏幕轻扫手势改变视图的背景颜色 (八).同时触发两个view的手势 手势之间是互斥的,如果你想同时触发蛇和龙的view,那么需要实现协议

iOS手势识别

一.手势识别与触摸事件 1.如果想监听一个view上面的触摸事件,可选的做法是: (1)自定义一个view (2)实现view的touches方法,在方法内部实现具体处理代码 2.通过touches方法监听view触摸事件,有很明显的几个缺点 (1)必须得自定义view (2)由于是在view内部的touches方法中监听触摸事件,因此默认情况下,无法让其他外界对象监听view的触摸事件 (3)不容易区分用户的具体手势行为 3.iOS 3.2之后,苹果推出了手势识别功能(Gesture Reco

iOS 手势识别

首先给大家解释一下为什么要学习手势识别? 如果想监听一个UIView上面的触摸事件,之前的做法是: 自定义一个UIView : 实现UIView的touches方法,在方法里面实现具体功能 透过touches监听UIView的触摸事件,有很明显的几个缺点: 1.必须要自定义UIView, 2.由于是在view内部的touches方法中监听触摸事件,因此默认情况下,无法让其他外界对象监听UIView的触摸事件 3.不容易区分用户的具体手势行为:(touches方法中根据坐标变换,判断x,y值的变化