- (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/...