UIGestureRecognizer手势的判断
来源:互联网 发布:优化网站的文件和资源 编辑:程序博客网 时间:2024/04/20 13:43
#import <UIKit/UIKit.h>
typedef enum{
LongPressGestureRecognizer = 0,
PanGestureRecognizer,
PinchGestureRecognizer,
RotationGestureRecognizer,
SwipeGestureRecognizer,
TapGestureRecognizer,
RecognizerTypeCount
}RecognizerType;
@interface FirstViewController : UIViewController <UIGestureRecognizerDelegate>{
}
@end
#import "FirstViewController.h"
@implementation FirstViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)performAlert:(NSString *)msg
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"手势" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alertView show];
[alertView release];
}
- (void)performSwipeGesture:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"performSwipeGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"轻扫"];
}
}
- (void)performRotationSwipeGesture:(UIRotationGestureRecognizer *)recognizer
{
NSLog(@"PerformRotationSwipeGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"旋转"];
}
}
- (void)performLongPressGesture:(UILongPressGestureRecognizer *)recognizer
{
NSLog(@"performLongPressGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"长按"];
}
}
- (void)performTapGesture:(UITapGestureRecognizer *)recognizer
{
NSLog(@"performTapGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"点击"];
}
}
- (void)performPinchGesture:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"performPinchGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"缩放"];
}
}
- (void)performPanGesture:(UIPanGestureRecognizer *)recognizer
{
NSLog(@"performPanGesture:");
if(recognizer.state == UIGestureRecognizerStateEnded){
[self performAlert:@"拖动"];
}
}
- (void)view:(UIView *)view addGestureRecognizer:(NSInteger)type
delegate:(id<UIGestureRecognizerDelegate>)delegate
{
UIGestureRecognizer *recognizer = nil;
SEL action = nil;
switch (type) {
case LongPressGestureRecognizer:
action = @selector(performLongPressGesture:);
recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:action];
break;
case PanGestureRecognizer:
action = @selector(performPanGesture:);
recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:action];
break;
case PinchGestureRecognizer:
action = @selector(performPinchGesture:);
recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:action];
break;
case RotationGestureRecognizer:
action = @selector(performRotationSwipeGesture:);
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:action];
break;
case SwipeGestureRecognizer:
action = @selector(performSwipeGesture:);
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:action];
break;
case TapGestureRecognizer:
action = @selector(performTapGesture:);
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:action];
((UITapGestureRecognizer *)recognizer).numberOfTapsRequired = 1;
break;
default:
return;
}
recognizer.delegate = delegate;
[view addGestureRecognizer:recognizer];
[recognizer release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i < RecognizerTypeCount; ++ i) {
[self view:self.view addGestureRecognizer:i delegate:self];
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view == self.view) {
return YES;
}
return NO;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end
typedef enum{
LongPressGestureRecognizer = 0,
PanGestureRecognizer,
PinchGestureRecognizer,
RotationGestureRecognizer,
SwipeGestureRecognizer,
TapGestureRecognizer,
RecognizerTypeCount
}RecognizerType;
@interface FirstViewController : UIViewController <UIGestureRecognizerDelegate>{
}
@end
#import "FirstViewController.h"
@implementation FirstViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)performAlert:(NSString *)msg
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"手势" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alertView show];
[alertView release];
}
- (void)performSwipeGesture:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"performSwipeGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"轻扫"];
}
}
- (void)performRotationSwipeGesture:(UIRotationGestureRecognizer *)recognizer
{
NSLog(@"PerformRotationSwipeGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"旋转"];
}
}
- (void)performLongPressGesture:(UILongPressGestureRecognizer *)recognizer
{
NSLog(@"performLongPressGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"长按"];
}
}
- (void)performTapGesture:(UITapGestureRecognizer *)recognizer
{
NSLog(@"performTapGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"点击"];
}
}
- (void)performPinchGesture:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"performPinchGesture:");
if(recognizer.state != UIGestureRecognizerStateEnded){
NSLog(@"not UIGestureRecognizerStateEnded");
}else {
[self performAlert:@"缩放"];
}
}
- (void)performPanGesture:(UIPanGestureRecognizer *)recognizer
{
NSLog(@"performPanGesture:");
if(recognizer.state == UIGestureRecognizerStateEnded){
[self performAlert:@"拖动"];
}
}
- (void)view:(UIView *)view addGestureRecognizer:(NSInteger)type
delegate:(id<UIGestureRecognizerDelegate>)delegate
{
UIGestureRecognizer *recognizer = nil;
SEL action = nil;
switch (type) {
case LongPressGestureRecognizer:
action = @selector(performLongPressGesture:);
recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:action];
break;
case PanGestureRecognizer:
action = @selector(performPanGesture:);
recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:action];
break;
case PinchGestureRecognizer:
action = @selector(performPinchGesture:);
recognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:action];
break;
case RotationGestureRecognizer:
action = @selector(performRotationSwipeGesture:);
recognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:action];
break;
case SwipeGestureRecognizer:
action = @selector(performSwipeGesture:);
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:action];
break;
case TapGestureRecognizer:
action = @selector(performTapGesture:);
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:action];
((UITapGestureRecognizer *)recognizer).numberOfTapsRequired = 1;
break;
default:
return;
}
recognizer.delegate = delegate;
[view addGestureRecognizer:recognizer];
[recognizer release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i < RecognizerTypeCount; ++ i) {
[self view:self.view addGestureRecognizer:i delegate:self];
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view == self.view) {
return YES;
}
return NO;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end
0 0
- UIGestureRecognizer手势的判断
- UIGestureRecognizer 各种手势的判断
- 手势UIGestureRecognizer
- 手势UIGestureRecognizer
- UIGestureRecognizer手势
- UIGestureRecognizer 手势
- 手势UIGestureRecognizer
- 手势UIGestureRecognizer
- UIGestureRecognizer手势
- UIGestureRecognizer手势
- UIGestureRecognizer手势
- UIGestureRecognizer手势
- UIGestureRecognizer手势
- ios的手势操作之UIGestureRecognizer浅析
- ios的手势操作之UIGestureRecognizer浅析
- ios的手势操作之UIGestureRecognizer浅析
- UIGestureRecognizer 真的很好用: 各种手势,
- ios的手势操作之UIGestureRecognizer浅析
- 百度地图修改鼠标样式
- QT数据库操作QSqlQuery
- 百度地图-修改marker图标(icon)
- HDU 2836 - Traversal (树状数组 + DP)
- 百度地图-点击事件问题
- UIGestureRecognizer手势的判断
- Step Two - 配置JAVA环境
- 数据信息图形化管理的明智选择-VisualNet
- cracked me.1. Acid burn
- 菜鸟练习PAT(四)
- 0、0和数值“零”在指针上下文中不是一回事
- 创建和删除快捷方式以及判断是否有快捷方式
- C# 消除游戏
- 油田(Oil Deposits)