1

在我的 iPhone 应用程序中,我使用 metaio sdk 和 UnfieyeMobileViewController。我已经自定义了视图以在 EAGLView 组件上显示相机视图,并且它工作正常。旋转设备时,相机方向没有改变的问题。而且,捕获的图像显示颠倒。这是我的代码,请检查:

在 ViewDidAppear 中:

UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;    
[self willAnimateRotationToInterfaceOrientation:interfaceOrientation duration:0];
    [super viewDidAppear:animated];

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    // adjust the rotation based on the interface orientation
    switch (interfaceOrientation) {
        case UIInterfaceOrientationPortrait:
            self.glView.transform = CGAffineTransformMakeRotation(0);
            break;

        case UIInterfaceOrientationPortraitUpsideDown:
            self.glView.transform = CGAffineTransformMakeRotation(M_PI);
            break;

        case UIInterfaceOrientationLandscapeLeft:  
            self.glView.transform = CGAffineTransformMakeRotation(M_PI_2);
            break;

        case UIInterfaceOrientationLandscapeRight:
            self.glView.transform = CGAffineTransformMakeRotation(-M_PI_2);
            break;
    }   

    // make sure the screen bounds are set correctly
    CGRect mainBounds = [UIScreen mainScreen].bounds;

    if( UIInterfaceOrientationIsLandscape(interfaceOrientation) )
    {
        int width = mainBounds.size.width;
        int height = mainBounds.size.height;
        mainBounds.size.width = height;
        mainBounds.size.height = width;
    }

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        // for iPhone the aspect ratio does not fit, so let's correct it
        if( UIInterfaceOrientationIsLandscape(interfaceOrientation) )
        {
            mainBounds.size.height = 360;   // because our renderer is a bit larger
            mainBounds.origin.y = -20;
        }
        else
        {
            mainBounds.size.width = 360;   // because our renderer is a bit larger
            mainBounds.origin.x = -20;            
        }
    }

    self.glView.frame = mainBounds;
}
4

0 回答 0