Fairly new at iOS/Objective C. I'm making mods to Apple's AVCam (video capture) sample code and would like to imitate the native camera's flip animation when switching between front and back cameras. It seems as if this would be easy but I can't get a handle on how it's done. Advice would be welcome.
Thanks!
Mark
Answer: A: You don't. Changing from front to rear camera while recording video is not a feature of the iPhone. Check the App Store, there are some apps that will allow that.
Flipping the cameraTap the Flip Camera button in the bottom-right corner to switch between front- and rear-facing cameras. You can use the front-facing camera to take a photo of yourself. You'll also use the front-facing camera for video-conferencing apps like FaceTime.
On Android, go to the Video option. Press the Capture icon to begin recording. Then double-tap anywhere on the screen to flip the camera. Once you are done recording, tap on the Save icon to download the video.
It is indeed a simple task. All you need to do is call the method transitionWithView
from UIView
right before changing the previewView
input.
If you're targeting iOS 8.0 or later, you can also easily add a blur effect.
Swift 2
let blurView = UIVisualEffectView(frame: previewView.bounds)
blurView.effect = UIBlurEffect(style: .Light)
previewView.addSubview(blurView)
UIView.transitionWithView(previewView, duration: 0.4, options: .TransitionFlipFromLeft, animations: nil) { (finished) -> Void in
blurView.removeFromSuperview()
}
Swift 3, 4, 5
let blurView = UIVisualEffectView(frame: previewView.bounds)
blurView.effect = UIBlurEffect(style: .light)
previewView.addSubview(blurView)
UIView.transition(with: previewView, duration: 0.4, options: .transitionFlipFromLeft, animations: nil) { (finished) -> Void in
blurView.removeFromSuperview()
}
Objective-C
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithFrame:_previewView.bounds];
blurView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
[_previewView addSubview:blurView];
[UIView transitionWithView:_previewView duration:0.4 options:UIViewAnimationOptionTransitionFlipFromLeft animations:nil completion:^(BOOL finished) {
[blurView removeFromSuperview];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With