您的位置:首页 > 其它

使用自动手势识别

2013-12-25 18:14 127 查看
UIGestureRecognizer的子类的实例,每个子类用于查找特定类型的手势,比如清扫、捏合、双击、单击

#import <UIKit/UIKit.h>

@interface>UIViewController

@property (retain,
nonatomic) IBOutlet
UILabel *label;

@end

#import "liViewController.h"

@interface
liViewController ()

@end

@implementation liViewController

- (void)viewDidLoad

{

[super
viewDidLoad];



self.view.backgroundColor = [UIColor
whiteColor];

//添加两个滑动的手势


UISwipeGestureRecognizer *vertical = [[UISwipeGestureRecognizer
alloc]initWithTarget:self
action:@selector(reportVerticalSwipe:)];

vertical.direction =
UISwipeGestureRecognizerDirectionUp;

[self.view
addGestureRecognizer:vertical];




UISwipeGestureRecognizer *Horizontal = [[UISwipeGestureRecognizer
alloc]initWithTarget:self
action:@selector(reportHorizontalSwipe:)];

Horizontal.direction =
UISwipeGestureRecognizerDirectionLeft;

[self.view
addGestureRecognizer:Horizontal];

}

- (void)reportHorizontalSwipe:(UIGestureRecognizer *)recognither

{

_label.text =
@"Horizontal swip detected";

[self
performSelector:@selector(eraseText)
withObject:nil
afterDelay:2];

}

- (void)eraseText

{


_label.text =
@"";

}

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

- (void)reportVerticalSwipe:(UIGestureRecognizer *)recgnither

{

_label.text =
@"Vertical swipe detected";

[self
performSelector:@selector(eraseText)
withObject:nil
afterDelay:2];

}

- (void)didReceiveMemoryWarning

{

[super
didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

- (void)dealloc {

[_label
release];

[super
dealloc];

}

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