5

在 iOS/Objective C 上相当新。我正在对 Apple 的AVCam(视频捕获)示例代码进行修改,并希望在前后摄像头之间切换时模仿本机摄像头的翻转动画。似乎这很容易,但我无法掌握它是如何完成的。建议将受到欢迎。

谢谢!

标记

4

1 回答 1

10

这确实是一项简单的任务。您需要做的就是在更改输入之前transitionWithViewUIView右侧调用该方法。previewView

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

斯威夫特 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()
}

斯威夫特 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];
}];
于 2015-12-13T07:54:41.023 回答