【问题标题】:iOS SDK: How to cause view to flip when switching camerasiOS SDK:如何在切换相机时导致视图翻转
【发布时间】:2012-05-16 12:37:23
【问题描述】:

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

谢谢!

标记

【问题讨论】:

    标签: ios animation video capture


    【解决方案1】:

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

    如果您的目标是 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];
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多