UiimagePicker Perview模式全屏,在Iphone 6和6+中自定义叠加

时间:2014-12-14 14:30:42

标签: ios iphone xcode6.1 iphone-6 iphone-6-plus

目前我正在使用UIImagePicker View进行自定义相机。我使用以下来修复Iphone 5中的Perview模式。我不得不为Iphone 6和6+提供支持。我应该通过编码为每个屏幕调整变换比例。

[[NSBundle mainBundle] loadNibNamed:@"overlayView" owner:self options:nil];
self.overlayView.frame = self.imagePickerController.cameraOverlayView.frame;
self.imagePickerController.cameraOverlayView = self.overlayView;
self.overlayView = nil;

//For iphone 5+
//Camera is 426 * 320. Screen height is 568.  Multiply by 1.333 in 5 inch to fill vertical
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points
self.imagePickerController.cameraViewTransform = translate;

CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
self.imagePickerController.cameraViewTransform = scale;

2 个答案:

答案 0 :(得分:1)

在此输入图片说明

CGSize screenSize = [[UIScreen mainScreen] bounds].size;
            // set the aspect ratio of the camera
            float heightRatio = 4.0f / 3.0f;
            // calculate the height of the camera based on the screen width
            float cameraHeight = screenSize.width * heightRatio;
            // calculate the ratio that the camera height needs to be scaled by
            float scale = screenSize.height / cameraHeight;
            // move the controller to the center of the screen
            self.imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight) / 2.0);
            // concatenate the scale transform
            self.imagePickerController.cameraViewTransform = CGAffineTransformScale(self.imagePickerController.cameraViewTransform, scale, scale);

但是由于这个原因,我也得到了在预览模式下不显示的额外区域。我以前得到同样的错误,但面积较小。如何仅捕获可见区域。

答案 1 :(得分:0)

我不确定是否还有其他解决方案。

但据我所知,您需要检查设备版本并相应地更改CGAffineTransformScale

有很多方法可以检查设备版本,以下是其中一种方法:

CGAffineTransform scale;

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
            if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {
                CGSize result = [[UIScreen mainScreen] bounds].size;


         CGFloat scale = [UIScreen mainScreen].scale;
            result = CGSizeMake(result.width * scale, result.height * scale);

            if(result.height == 960) {
                NSLog(@"iPhone 4, 4S Resolution");
                scale = CGAffineTransformScale(translate, sx, sy); // sx and sy are CGFloats
            }
            else if(result.height == 1136) {
                NSLog(@"iPhone 5, 5C, 5S Resolution");
                scale = CGAffineTransformScale(translate, sx, sy); // sx and sy are CGFloats
            }
            else if(result.height == 1334) {
                NSLog(@"iPhone 6 Resolution");
                scale = CGAffineTransformScale(translate, sx, sy); // sx and sy are CGFloats
            }
            else if(result.height == 1920) {
                NSLog(@"iPhone 6 Plus Resolution");
                scale = CGAffineTransformScale(translate, sx, sy); // sx and sy are CGFloats
            }
        }
        else{
            NSLog(@"Standard Resolution");
        }
    }

准备好比例参考后,您可以设置:

self.imagePickerController.cameraViewTransform = scale;

希望这有帮助。