Gesture - Long Press
来源:互联网 发布:linux 虚拟文件系统 编辑:程序博客网 时间:2024/06/06 09:05
@property (nonatomic, strong) UIButton *dummyButton;
@property (nonatomic, strong) UILongPressGestureRecognizer *longPressGesture;
-(void)initButton {
self.btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.btn.frame = CGRectMake(0.0f,0.0f,72.0f,37.0f);
[self.btn setTitle:@"My button" forState:UIControlStateNormal];
self.btn.center = self.view.center;
[self.view addSubview:self.btn];
}
- (void)addGesture {
self.longPressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLongPressGestures:)];
self.longPressGesture.numberOfTouchesRequired = 2;
/* Maximum 100 points of movement allowed before the gesture is recognized,default 10 points */
self.longPressGesture.allowableMovement = 100.0f;
/* The user must press 2 fingers (numberOfTouchesRequired) for at least 1 second for the gesture to be recognized */
self.longPressGesture.minimumPressDuration = 1.0;
[self.view addGestureRecognizer:self.longPressGesture];
}
- (void) handleLongPressGestures:(UILongPressGestureRecognizer *)paramSender{
/* 确保与其它的长按手势区分开来 */
if ([paramSender isEqual:self.longPressGesture]){
if (paramSender.numberOfTouchesRequired == 2){
CGPoint touchPoint1 = [paramSenderlocationOfTouch:0 inView:paramSender.view];
CGPoint touchPoint2 = [paramSender locationOfTouch:1 inView:paramSender.view];
CGFloat midPointX = (touchPoint1.x + touchPoint2.x) / 2.0f;
CGFloat midPointY = (touchPoint1.y + touchPoint2.y) / 2.0f;
CGPoint midPoint = CGPointMake(midPointX, midPointY);
self.btn.center = midPoint;
}
}
}
postscript:若在长按过程中接收到来电,则此手势状态改为UIGestureRecognizerStateCancelled
- Gesture - Long Press
- Andorid Long press event handling
- 8.4 Detecting Long Press Gestures
- Long CLick 和Long Press区别
- 长按(long Press)手势
- 给UICollectionViewCell绑定手势 long press举例
- Press
- Android WebView Long Press长按保存图片到手机
- Android WebView Long Press长按保存图片到手机
- Gesture
- Gesture
- Press Release
- Simple:Press
- Press Events
- Gesture Detector
- Android Gesture
- android Gesture
- 手势 gesture
- CCLabelTTF的多行显示(仅限中文)
- hadoop学习笔记之-NFS配置
- I2S,PCM,AC97 音频总线
- 数据通信之cjson
- 还是c#的toolstrip简单
- Gesture - Long Press
- C#中数据类型的托管
- 链接过程
- 解析swf的RECT结构
- 给Linux系统/网络管理员准备的Nmap命令的29个实用范例
- PHP Simple HTML DOM解析器使用入门
- 安装完win7+Ubuntu双系统,无法进入Win7,A read disk error occurred问题的解决
- windows窗口样式速查参考
- 编码 统计连续字符串中连续字母的个数。