UIImagePickerController cameraViewTransform在iOS 4中的行为不同 [英] UIImagePickerController cameraViewTransform acts differently in iOS 4

查看:373
本文介绍了UIImagePickerController cameraViewTransform在iOS 4中的行为不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的iPhone和SDK升级到iOS 4.0.1,现在我的应用程序运行方式与在iOS 3.x中运行方式不同。



我的应用程序使用UIImagePickerController与自定义cameraOverlayView(我会在这篇文章中禁止)。主要的是,我需要看到iphone相机在全屏模式。



我使用XCode模板项目创建了一个基于视图的应用程序,名为CameraTransform ,所以我有两个类: CameraTransformAppDelegate CameraTransformViewController ,确定!在 CameraTransformViewController viewDidAppear 方法中,我输入以下代码:

   - (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

UIImagePickerController * picker = [[UIImagePickerController alloc] init];

picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;

// [self configurePicker_FirstAttempt:picker];用这个!
// [self configurePicker_SecondAttempt:picker];使用这个!

[self presentModalViewController:picker animated:YES];
}

- (void)configurePicker_FirstAttempt:(UIImagePickerController *)picker {
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;

//不需要(使用默认值)
//picker.toolbarHidden = YES;
//picker.wantsFullScreenLayout = YES;
}

- (void)configurePicker_SecondAttempt:(UIImagePickerController *)picker {

//转换全屏支持的值
CGFloat cameraTransformX = 1.0;
CGFloat cameraTransformY = 1.12412;

picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform,cameraTransformX,cameraTransformY);
}

使用/ i运行项目:





注意:


  1. 在iOS 3.x中,我使用第三种方法(两种方法取消注释)来配置选择器,

  2. 我检查了 picker.cameraViewTransform 原始值(缩放前),并设置

  3. picker.view.frame 设置为屏幕边界的(0.0,0.0,320.0, 480.0)

  4. 我尝试将翻译连接到 picker.cameraViewTransform (缩放后),如下所示: CGAffineTransformTranslate(picker.cameraViewTransform,0.0,20.0); ,我意识到有一部分相机视图被隐藏(也许它的原点不是0.0,0.0)所以我在屏幕上获得了更多的摄像头视图。

看起来像在新的SDK UIImagePickerController已经改变了某种方式,也许



有没有人有这个问题?

解决方案


ios 4.0幻数1936/320 = 6.05,2592 / 6.05 = 428,480-428 = 52 52 /(428/2)= 0.24299 + 1 = 1.24299 >

ios 3.0幻数1536/320 = 4.8 2048 / 4.8 = 427 480-427 = 53 53/427 = 0.121412 + 1 = 1.12412


< blockquote>

这是关系cameraresolution-screenresolution



对于iOS 3.0 cameraViewTransform是从顶部应用,所有的高度。但在iOS4中,它是从框架的中心应用,所以你必须使用一半的高度。您必须向下移动框架(52/2)才能将框架置于中心。


I upgraded both my iPhone and SDK to iOS 4.0.1 and now my App doesn't run the same way it was running in iOS 3.x.

My App uses the UIImagePickerController with a custom cameraOverlayView (which I'll suppress in this post). The main point is that I need to see the iphone camera in fullscreen mode. To go straight to the problem, I'll put some code and screenshots to explain what's happening.

I created a View-Based Application using the XCode Template projects named "CameraTransform", so I got two classes: CameraTransformAppDelegate and CameraTransformViewController, ok! In the CameraTransformViewController's viewDidAppear method I put the following code:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    UIImagePickerController* picker = [[UIImagePickerController alloc] init];

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;        
    picker.delegate = self;

    //[self configurePicker_FirstAttempt:picker];   Use this!
    //[self configurePicker_SecondAttempt:picker];  Use this too!

    [self presentModalViewController:picker animated:YES];
}

- (void)configurePicker_FirstAttempt:(UIImagePickerController*) picker {
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;

    // not needed (use defaults)
    //picker.toolbarHidden = YES;
    //picker.wantsFullScreenLayout = YES;
}

- (void)configurePicker_SecondAttempt:(UIImagePickerController*) picker {

    // Transform values for full screen support
    CGFloat cameraTransformX = 1.0;
    CGFloat cameraTransformY = 1.12412;

    picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, cameraTransformX, cameraTransformY);
}

Running the project with/i got:

NOTE:

  1. In iOS 3.x I used the third approach (both methods uncommented) to configure the picker, which was show in the fullscreen mode without the "black bar" at the bottom.
  2. I inspected the picker.cameraViewTransform original value (before being scaled) and it is set to Identity (as expected).
  3. The picker.view.frame is set to the screen bounds's (0.0, 0.0, 320.0, 480.0)
  4. I tried to concatenate a translation to the picker.cameraViewTransform (after being scaled), like this: CGAffineTransformTranslate(picker.cameraViewTransform, 0.0, 20.0); and I realized that there was some part of the "camera view" that was hidden (maybe it's origin wasn't the 0.0, 0.0), so I got more "camera view" on screen.

It looks like in the new SDK the UIImagePickerController has changed in some way, maybe the camera controls have different sizes os something alike.

Has anyone had this problem?

解决方案

ios 4.0 Magic number 1936/320= 6.05 , 2592/6.05 = 428 , 480-428 = 52 52/(428/2)=0.24299 +1=1.24299

ios 3.0 Magic number 1536/320=4.8 2048/4.8=427 480-427=53 53/427=0.121412 +1=1.12412

That is the relationship cameraresolution-screenresolution

For iOS 3.0 the cameraViewTransform is applied from the top so you have to use all the height. But in iOS4 it is applied from the center of the frame so you have to use the half of the height. And you have to move the frame down (52/2) to leave the frame in the center.

这篇关于UIImagePickerController cameraViewTransform在iOS 4中的行为不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆