フロントカメラからバックカメラへのカメラアプリの遷移を模倣しようとしています.. UIViewAnimationOptionTransitionFlipFromLeft を使用しています..
私の現在の方法は、前面カメラで写真を撮り、背面カメラに切り替え、背面カメラで写真を撮り、それらを2つのUIImageViewにロードし、画像ビューで遷移を実行することです..(プロセスで現在のカメラストリームを非表示にします)..
問題は、前面カメラから背面カメラに切り替える呼び出しを行うと、cameraView (AVCapturePreviewLayer) がビューを非表示にする前に即座にビューを切り替えることです (これは最後の行の flipCameraToFront で発生します.. [_captureSession commitConfiguration])...
うまくいけば、これは理にかなっています。一部のコードを省略しました。それが役立つと思われる場合は、残りのコードを投稿します。
どんな助けでも大歓迎です、ありがとう
//class:RecordViewController
//iVars for this class..
RecordVideoHandler *_recordHandler;
UIImage *_firstImageForFlip;
UIImage *_secondImageForFlip;
UIImageView *_firstImageViewForFlip;
BOOL isUsingFrontInput;
AVCaptureVideoPreviewLayer *_capturePreviewLayer;
UIView *_capturePreviewView;
- (void)doCameraFlip:(UIButton *)sender
{
[_recordHandler addStillImageOutput];
//This method calls imageReturned:(UIImage *)inImage;
[_recordHandler captureAndReturnStillImage];
}
- (void)imageReturned:(UIImage *)inImage{
if(_firstImageForFlip == nil){
[_capturePreviewLayer setFrame:CGRectZero];
_firstImageForFlip = inImage;
_firstImageViewForFlip = [[UIImageView alloc] initWithImage:_firstImageForFlip];
if(isUsingFrontInput)
[_firstImageViewForFlip setTransform:CGAffineTransformMakeScale(-1.0, 1.0)];
[_firstImageViewForFlip setFrame:_capturePreviewView.bounds];
[_capturePreviewView addSubview:_firstImageViewForFlip];
if(isUsingFrontInput){
[_recordHandler flipCameraToBack];
}else{
[_recordHandler flipCameraToFront];
}
[_recordHandler captureAndReturnStillImage];
}else{
_secondImageForFlip = inImage;
[_recordHandler removeStillImageOutput];
[self finishCameraFlip];
}
}
- (void)finishCameraFlip{
UIImageView *secondImageView = [[UIImageView alloc] initWithImage:_secondImageForFlip];
[secondImageView setFrame:_capturePreviewView.bounds];
if(!isUsingFrontInput)
[secondImageView setTransform:CGAffineTransformMakeScale(-1.0, 1.0)];
[UIView transitionWithView:_capturePreviewView duration:3.3f
options:UIViewAnimationOptionTransitionFlipFromLeft animations:
^{
[_firstImageViewForFlip removeFromSuperview];
[_capturePreviewLayer setFrame:_capturePreviewView.bounds];
[_capturePreviewView addSubview:secondImageView];
} completion:
^(BOOL finished){
[secondImageView removeFromSuperview];
}];
isUsingFrontInput = isUsingFrontInput ? NO : YES;
_firstImageForFlip = nil;
_secondImageForFlip = nil;
}
クラス:RecordVideoHandler
//iVars for this class..
AVCaptureSession *_captureSession;
- (void)flipCameraToFront
{
[_captureSession beginConfiguration];
for (AVCaptureInput *input in _captureSession.inputs) {
if (input == _captureRearInput) {
[_captureSession removeInput:_captureRearInput];
[_captureSession addInput:_captureFrontInput];
}
}
_currentCaptureDevice = _captureDeviceFrontFacing;
[_captureSession commitConfiguration];
}