How to implement a volume key shutter for iPhone?

后端 未结 5 864
[愿得一人]
[愿得一人] 2020-12-07 23:24

I want to implement the same behavior with the native camera of iOS5:

  • press the volume + button to take a photo

What\'s the

5条回答
  •  孤城傲影
    2020-12-08 00:01

    I call this method from viewDidAppear

    -(void) startTrackingVolume
    {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
        [[AVAudioSession sharedInstance] setActive:YES error:nil];
    
        if (!self.volumeView) {
            // put it somewhere outside the bounds of parent view
            self.volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-100, -100, 10, 0)];
            [self.volumeView sizeToFit];
        }
    
        if (!self.volumeView.superview) {
            [self.view addSubview:self.volumeView];
        }
    }
    

    In viewWillDisappear in call

    [[AVAudioSession sharedInstance] setActive:NO error:nil];
    

提交回复
热议问题