- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor whiteColor];
UIButton * roundBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[roundBtn setFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width-60)/2, 200, 60, 60)];
[roundBtn setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:roundBtn];
_roundBtn = roundBtn;
UILongPressGestureRecognizer * longGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longGesture:)];
[roundBtn addGestureRecognizer:longGesture];
}
-(void)longGesture:(UILongPressGestureRecognizer *)gesture
{
int sendState = 0;
CGPoint point = [gesture locationInView:_roundBtn];
if (point.y<0)
{
NSLog(@"松开手指,取消发送");
sendState = 1;
}
else
{
//重新进入长按录音范围内
sendState = 0;
}
//手势状态
switch (gesture.state) {
case UIGestureRecognizerStateBegan:
{
//NSLog(@"开始");
NSLog(@"这里开始录音");
}
break;
case UIGestureRecognizerStateEnded:
{
//NSLog(@"长按手势结束");
if (sendState == 0)
{
NSLog(@"结束录音并发送录音");
}
else
{
//向上滑动取消发送
NSLog(@"取消发送删除录音");
}
}
break;
case UIGestureRecognizerStateFailed:
//NSLog(@"长按手势失败");
break;
default:
break;
}
}
长按手势简单示例
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1、手势识别器——UIGestureRecognizer 介绍在ios开发中,除了有关触摸的这组方法来控制使用用者...
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义:转载:http://www.cnblogs.com/...