2

フロントカメラからバックカメラへのカメラアプリの遷移を模倣しようとしています.. 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];
}
4

1 に答える 1

6

誰かが疑問に思っていたら、私はそれを理解しました。次の実行ループを待つために performSelectors を使用する必要がありました。これは、カメラが即座に反転したのに対し、実行ループまたは何かの後にビューが待機していたためです...詳細についてはわかりませんが、コードは次のとおりです。

- (void)doCameraFlip:(UIButton *)sender
{
    NSLog(@"doCameraFlip");
    [_recordHandler addStillImageOutput];    
    [_recordHandler captureAndReturnStillImage];    
}
- (void)imageReturned:(UIImage *)inImage{
    [_recordHandler removeStillImageOutput];            
    _imageViewForFlip= [[UIImageView alloc] initWithImage:inImage];
    [_imageViewForFlip setFrame:_containerView.bounds];
    [_containerView addSubview:_imageViewForFlip];


    [self performSelector:@selector(cfe) withObject:nil afterDelay:0.0f];
    [self performSelector:@selector(cfe2) withObject:nil afterDelay:0.0f];

}
- (void)cfe{
    if(isUsingFrontInput){
        [_recordHandler flipCameraToBack];
    }else{
        [_recordHandler flipCameraToFront];
    }

}
- (void)cfe2{
    [UIView transitionWithView:_containerView duration:3.0f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
        [_imageViewForFlip removeFromSuperview]; 
        [_containerView addSubview:_capturePreviewView]; 
    } completion:nil];
}
于 2012-01-30T16:41:49.840 に答える