iOS SDK:如何在切换摄像机时使视图翻转

mpe*_*urn 5 video animation capture ios

在iOS/Objective C上相当新.我正在为Apple的AVCam(视频捕捉)示例代码制作mod,并希望在前后摄像头之间切换时模仿原生相机的翻转动画.似乎这很容易,但我无法理解它是如何完成的.建议是值得欢迎的.

谢谢!

标记

brn*_*nes 8

这确实是一项简单的任务.所有你需要做的是调用该方法transitionWithViewUIView改变前右previewView输入.

如果您的目标是iOS 8.0或更高版本,您还可以轻松添加模糊效果.

在Swift中:

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()
}
Run Code Online (Sandbox Code Playgroud)

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];
}];
Run Code Online (Sandbox Code Playgroud)