views:

555

answers:

3

Hi folks, 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?

A: 

Hi I have the same problem No idea what is causing it ;-(

Anyone?

Jack
+1  A: 

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.

Mark Beaton
A: 

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.

Tom