UIImagePickerController cameraViewTransform acts d

2020-02-26 10:45发布

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?

4条回答
三岁会撩人
2楼-- · 2020-02-26 11:11

I'm finding the new scale transform for the iPhone 4 to be ~1.25 (instead of ~1.12).

I spent a few minutes trying to figure out where these magic numbers come from - I assume there's some sort of relationship between the screen resolution & the camera resolution, but I couldn't figure it out in a hurry...

If someone does, please post an answer - I hate magic numbers.

FYI the camera res of the iPhone 4 is 2592x1936, while the iPhone 3GS is 2048x1536.

查看更多
Evening l夕情丶
3楼-- · 2020-02-26 11:14

I am not sure about iOS 3.0 but for iOS 4.0 the cameraViewTransform is applied from the center of the frame. You can verify this by first applying a translation transform.

CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 27.0);
imagePickerController.cameraViewTransform = translate;

You can see that this moves the view to the center. Next apply the scaling transform and you will see that it fills the screen.

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

If the scaling transform alone works for iOS 3 and company then the transform is applied to the a different anchor point like center top. You should always scale linearly in both directions or your image will be skewed.

查看更多
做个烂人
4楼-- · 2020-02-26 11:22

CGAffineTransformMakeTranslation will not work directly on cameraViewTransform. So, use CGAffineTransformScale to apply CGAffineTransformMakeTranslation.

float yOffset = 44.0;
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, yOffset);
self.cameraFeed.cameraViewTransform = CGAffineTransformScale(translate, 1, 1);
查看更多
▲ chillily
5楼-- · 2020-02-26 11:30

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.

查看更多
登录 后发表回答