首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

容易的手势操作

2012-08-03 
简单的手势操作头文件:?#define kMinimumGestureLength25#define kMaximumVariance5#import UIKit/UIKit.

简单的手势操作

头文件:

?

#define kMinimumGestureLength  25#define kMaximumVariance  5#import <UIKit/UIKit.h>@interface TouchesViewController : UIViewController {IBOutlet UILabel *label;CGPoint gestureStartPoint;}@end

?

实现文件:

?

#import "TouchesViewController.h"@implementation TouchesViewController- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {UITouch *touch = [touches anyObject];gestureStartPoint = [touch locationInView:self.view];}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{UITouch *touch = [touches anyObject];CGPoint currentPosition = [touch locationInView:self.view];    CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);if(deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){label.text = @"Horizontal Swipe Detected";[self performSelector:@selector(eraseText) withObject:nil afterDelay:3];}else if(deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){label.text = @"Vertical Swipe Detected";[self performSelector:@selector(eraseText) withObject:nil afterDelay:3];}}- (void)eraseText{label.text = @"";}- (void)dealloc {[super dealloc];}@end

?

热点排行