0

I'm making a function using Camera(AVCapture input/output). Now I have a trouble like below.

'layoutSubviews' is not called when iPhone is rotated upsidedown(180 degree) at one time.
(If rotate in 2 step 90 degree and 90 degree, 'layoutSubviews' is called in each rotation)

I'm using AVCaptureVideoPreviewLayer to display camera output.
And to rotate the preview layer, I wrote the code like below.

- (void)layoutSubviews
{
    [super layoutSubviews];   
    [_previewLayer setFrame:self.bounds];
    [self setVideoOrientation];
}

- (void)setVideoOrientation
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait;

    switch (orientation) {
        case UIInterfaceOrientationPortrait:
            videoOrientation = AVCaptureVideoOrientationPortrait;
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
            break;
        case UIInterfaceOrientationLandscapeRight:
            videoOrientation = AVCaptureVideoOrientationLandscapeRight;
            break;
        default:
            break;
    }

    [_previewLayer.connection setVideoOrientation:videoOrientation];
}

Could you please tell me, if you know, a good solution to call 'layoutSubviews' in 180 degree rotation at one time.

M.Masa
  • 532
  • 4
  • 20
  • I'm not sure but I think layoutSubviews just be called when main view is updated frame. I think you can try to 'resize' or refresh main view frame when device rotate first. – Mục Đồng Jul 27 '15 at 02:23
  • @MụcĐồng Thanks. The view is main view (Set by `setView` in `loadView` method of ViewController). So `layourSubviews` is called in 90 degree rotatoin. I'd like to know how to call `laytoutSubviews` in 180 degree rotation. – M.Masa Jul 27 '15 at 04:53
  • Now I took a workaround. Call `[self.view setNeedsLayout;` in ViewController's `willAnimateRotationToInterfaceOrientation`. Maybe it's not best solution but works correctly so far. – M.Masa Jul 28 '15 at 02:42

0 Answers0