1、viewDidLoad中
//按住录音按钮添加长按手势
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.longPressBtn addGestureRecognizer:longPressGesture];
2、//长按录音
-(void)longPress:(UILongPressGestureRecognizer*)gusture{
if(gusture.state==UIGestureRecognizerStateBegan){
NSLog(@"startPress");
[self startRcd];
}else if(gusture.state==UIGestureRecognizerStateEnded){
[self stopRcd];
NSLog(@"endPress");
}
}
这篇博客介绍了如何在iOS应用中利用UILongPressGestureRecognizer实现录音功能。通过在viewDidLoad中添加长按手势到录音按钮,并在longPress方法中根据手势状态开始或结束录音。这是一个基础的iOS交互实现案例。
1505

被折叠的 条评论
为什么被折叠?



