How to implement a volume key shutter for iPhone?

后端 未结 5 857
[愿得一人]
[愿得一人] 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:04

    Building on huxia's code, this works on ios5+, no need to run the code every time it becomes active, just run it once in the beginning.

    // these 4 lines of code tell the system that "this app needs to play sound/music"
    AVAudioPlayer* p = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"photoshutter.wav"]] error:NULL];
    [p prepareToPlay];
    [p stop];
    
    //make MPVolumeView Offscreen
    CGRect frame = CGRectMake(-1000, -1000, 100, 100);
    MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:frame];
    [volumeView sizeToFit];
    [self.view addSubview:volumeView];
    

提交回复
热议问题