UIImagePickerController cameraViewTransform在iOS 4中的行为不同 [英] UIImagePickerController cameraViewTransform acts differently in 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运行项目:
- 两个
configurePicker_FirstAttempt
和configurePicker_SecondAttempt
方法调用已注释: defaultPicker.png 。 - 只有
configurePicker_SecondAttempt
方法调用已注释: configurePicker_FirstAttempt.png 。 - 两个
configurePicker_FirstAttempt
和configurePicker_SecondAttempt
方法调用取消注释: configurePicker_SecondAttempt.png 。
注意:
- 在iOS 3.x中,我使用第三种方法(两种方法取消注释)来配置选择器,
- 我检查了
picker.cameraViewTransform
原始值(缩放前),并设置 -
picker.view.frame
设置为屏幕边界的(0.0,0.0,320.0, 480.0) - 我尝试将翻译连接到
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
andCameraTransformViewController
, ok! In theCameraTransformViewController
'sviewDidAppear
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:
- both
configurePicker_FirstAttempt
andconfigurePicker_SecondAttempt
method calls commented: defaultPicker.png.- only
configurePicker_SecondAttempt
method call commented: configurePicker_FirstAttempt.png.- both
configurePicker_FirstAttempt
andconfigurePicker_SecondAttempt
method calls uncommented: configurePicker_SecondAttempt.png.NOTE:
- 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.
- I inspected the
picker.cameraViewTransform
original value (before being scaled) and it is set to Identity (as expected).- The
picker.view.frame
is set to the screen bounds's (0.0, 0.0, 320.0, 480.0)- 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屋!