使用AVFoundation长按手势开始停止录制

时间:2015-04-28 15:32:26

标签: ios objective-c avfoundation long-press

您好我想用长按手势开始在Objective-C中使用AVFoundation编码停止录制。

我知道如何开始录制并使用另一个按钮停止录制,但不能用同一个按钮完成录制。

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在

中设置UILongPressGestureRecognizer

- (void) viewDidLoad {....}

UILongPressGestureRecognizer *gesture1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
//[gesture1 setDelegate:self]; you won't need this most probably if detecting the long press is your only expectation from the gesture recognizer
[gesture1 setMinimumPressDuration:1];
[self addGestureRecognizer:gesture1];
//instead of [self addGest... you can try [self.view addGest.. as follows:
[self.view addGestureRecognizer:gesture1];

当用户按下视图至少1秒时,将触发此功能:

-(void)longPressed:(UIGestureRecognizer *)longPress {
    if(([longPress state] == UIGestureRecognizerStateEnded) || ([longPress state] == UIGestureRecognizerStateEnded)) {
        NSLog(@"long press ended");
        //[self stopRecording];
    }
    else if([longPress state] == UIGestureRecognizerStateBegan) {
        NSLog(@"long press detected");
        //[self startRecording];
    }
}

而不是您使用UIButton的旧方式:

-(IBAction) buttonPressed: (id)sender {
    NSLog(@"button press detected");
    //[self startRecording];
}