使用自动手势识别

来源:互联网 发布:js设置div的style 编辑:程序博客网 时间:2024/06/05 03:40

UIGestureRecognizer的子类的实例,每个子类用于查找特定类型的手势,比如清扫、捏合、双击、单击

#import <UIKit/UIKit.h>


@interface>UIViewController

@property (retain,nonatomic) IBOutletUILabel *label;


@end



#import "liViewController.h"


@interface liViewController ()


@end


@implementation liViewController


- (void)viewDidLoad

{

    [superviewDidLoad];

    

    self.view.backgroundColor = [UIColorwhiteColor];

//添加两个滑动的手势  

   UISwipeGestureRecognizer *vertical = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(reportVerticalSwipe:)];

    vertical.direction =UISwipeGestureRecognizerDirectionUp;

    [self.viewaddGestureRecognizer:vertical];

    

   UISwipeGestureRecognizer *Horizontal = [[UISwipeGestureRecognizeralloc]initWithTarget:selfaction:@selector(reportHorizontalSwipe:)];

    Horizontal.direction =UISwipeGestureRecognizerDirectionLeft;

    [self.viewaddGestureRecognizer:Horizontal];

}

- (void)reportHorizontalSwipe:(UIGestureRecognizer *)recognither

{

    _label.text =@"Horizontal swip detected";

    [selfperformSelector:@selector(eraseText)withObject:nilafterDelay:2];

}

- (void)eraseText

{

   _label.text =@"";

}

//实现手势所带来的实际功能

- (void)reportVerticalSwipe:(UIGestureRecognizer *)recgnither

{

    _label.text =@"Vertical swipe detected";

    [selfperformSelector:@selector(eraseText)withObject:nilafterDelay:2];

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (void)dealloc {

    [_labelrelease];

    [superdealloc];

}

@end


0 0
原创粉丝点击