Issue with UIImagePicker rotation - iphone

I have set an UIIMagePicker in my app with:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.showsCameraControls = NO;
imagePickerController.navigationBarHidden = YES;
imagePickerController.toolbarHidden = YES;
imagePickerController.wantsFullScreenLayout = YES;
//imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, 1.0, 1.3);
imagePickerController.delegate = self.overlayView;
[self.view addSubview:imagePickerController.view];
imagePickerController.cameraOverlayView =self.overlayView.view;
All good and fine while the app is in portrait mode. Yet, if I rotate it in landscape a strange issue happen: a black bar appears on the right side and the view is 'rotated', in the sense that if I move the iPhone upward the image moves to the side and viceversa.
If I start in landscape mode, the black bar does not appear (it conversely shows when I rotate to portrait mode on the bottom), but the funny rotating behavior happens all the same.
In both cases the overlay screen seems to fill the screen and also correctly handle rotation.
What might be the issue and how to fix it?
Thanks, Fabrizio

Related

Removing Camera Controls from UIImagePicker - How to Scale Up to Full Screen - iPhone / iPad

I have the below code in my app which displays a UIImagePicker minus the camera controls.
#define CAMERA_SCALAR 1.32
#implementation CameraViewController
- (id)init {
// Remove standard controls from UIImagePicker and make full screen
if (self = [super init]) {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.navigationBarHidden = YES;
self.toolbarHidden = YES;
self.wantsFullScreenLayout = YES;
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, 1, CAMERA_SCALAR);
}
return self;
}
Initially when I removed set showsCameraControls to NO I got a black bar on the screen where the controls had been. To offset this I added in the self.cameraViewTransform line to scale up the view.
This works, however it distorts the image. I think what I need to do is also scale the height by the same ratio as the width.
Can anyone advise me on the best way to do this ?
Thanks in advance !
I may be misinterpreting your question, but to scale the width as well, you can
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, CAMERA_SCALAR, CAMERA_SCALAR);
instead of
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, 1, CAMERA_SCALAR);
But of course, this will push the sides of the camera view out of screen.
In principle, I think there is no best choice in this case (showing exactly what the camera shows in fullscreen), because the origin of the problem is the difference of the aspect ratio of the screen/camera. You either have to miss part of the view, or distort the view, is my thinking.

Rotate the screen manually to Landscape and there is a white bar left behind on left of screen where the old status bar was placed

I have one screen in my app that I need in portrait as I use a video camera on this screen.
So I load my view then call this method:
- (void)rotate
{
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +80.0);
[self.tabBarController.view setTransform:landscapeTransform];
self.tabBarController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
self.tabBarController.view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
There is a 20 pixel wide white area along left hand side of the screen, where the status bar used to be drawn while the screen was in portrait mode.
Same problem exists when I replace the self.tabBarController.view in the above code with self.view
Maybe there is someway to target the very root view of the app if self.view is not that view.
The xib for this view is 480 pixels in size. Can anybody give me some advise as how to fix this problem?
When I take this view out and make appear in a an app without any navbar and placed directly on the main view it transforms ok without the white space on the left.
Many Thanks,
-Code
You should trust rotation to ios default orientation changes.
In order to programmatically rotate to desired orientation:
//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];
//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];
Hopefully it will help!
P.S.Tested on sdk 3.2.5 ios 5.0.1.

cameraOverlayView problem on iOS 4.3

I'm using an picker Controller with a cameraOverlayView to display an image of a product in the camera view. The product image is resized before applying on the overlay.
It works fine on iOS 4.2 but on iOS 4.3 the product image is displayed full size.
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];
// Resize
if(imgView.frame.size.height == 480)
{
//Portrait
imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
// Landscape
imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}
imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;
pickerController.cameraOverlayView = (UIView *) imgView;
I changed the frame of the UIImageView I use as overlay but it's still displayed at 320*480.
I know that the cameraOverlayView have been modified in iOS 4.3 but I don't know what has changed and what I have to do to correct my application.
Thanks for your help.
In iOS 4.3 the overlay view is stretched to full screen. Because you set the content mode to aspect fit, the image is stretched to fit the new view size which is 320x480.
You need to make a transparent UIView that is fullscreen, add the imageview to that view and make the UIView the new overlay view.
UIView *fullscreenView = [[UIView alloc] initWithFrame:CGRectZero];
fullscreenView.backgroundColor = [UIColor clearColor];
....
[fullscreenView addSubview:imgView];
pickerController.cameraOverlayView = fullscreenView;
Found this article that seems to fit the bill. The long and short of it is to use
- (UIImage *)
resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality;
Comment out this line in your code
imgView.clipsToBounds = NO;
It should work.
If you really want to clip, #slf 's answer should help.
try setting these properties of UIImagePicker:
mImagePickerController.showsCameraControls = NO;
mImagePickerController.navigationBarHidden = YES;
mImagePickerController.toolbarHidden = YES;
mImagePickerController.wantsFullScreenLayout = YES;
My problem was actually that a UIImagePicker displayed full-screen on iOS5 did not work on iOS4.3, on an iPad. I was starting the image picker up offscreen, then animating it into view... You would see the shutter image open up, but then the camera view itself was simply transparent with no camera output.
My solution was to not animate that in for iOS4.3 on the iPad. It seems that having the camera view started offscreen was leaving the camera rendering part behind (fixed as I noted in iOS5).
This answer is not quite right for the original question but I place it here for someone that comes into the same issue and hits this question as I did.

MPMediaPickerController orientation on iPad

How can I set correct orientation of MPMediaPickerController ?
I've return YES in shouldAutorotateToInterfaceOrientation, but i have bad frame for Landscape (if show MPMediaPickerController in Portrait first, and conversely).
I've rotating my device chaotically and sometime frame set to correct himself!
I've find the method to set frame by rotating - need rotate to 180 degreess.
For example, if you have good frame in Portrait, when you rotate to Landscape - you have bad frame (from Portatait), but if you rotate to other landscape (to 180 degreess), then frame set to Landscape...
Why ?
How can i set the frame after rotation correct always ?
regards,
Not sure whether you are interested in the solution or not, since you asked this in 2010.
Anyway, after a few searches here is what I found:
MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.
In order to make the MPMediaPicker appear nicely in landscape orientation, we can make use of PopOverController. Basically, we create a pop over, and insert the picker into it. PopOverController, when displayed properly from the rootViewController, will indeed follow the orientation of the device.
Here is the rough code. It works, but needs some cleaning up. Probably best you check whether
the popover is nil or not, otherwise it will just stack up on itself each time the user tap on the button.
- (IBAction)showMediaPicker:(id)sender
{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES;
mediaPicker.prompt = #"Select musics...";
UIPopoverController *colorPickerPopover = [[[UIPopoverController alloc]
initWithContentViewController:mediaPicker] retain];
[colorPickerPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
A little more note: this IBAction is tied to a Toolbar Bar button.
I'm simply pushing it onto my navigation controller:
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = #"Select songs...";
[[self navigationController] pushViewController:mediaPicker animated:YES];
Granted this only works in the context of a navigation controller, but it works and is simple!
here is some sample code you can try it one , after rotation you have to set media palyer view in center of self.view, here some sample code... you have to add MediaPlayer Framework at first....
NSString* moviePath = [[NSBundle mainBundle] pathForResource:#"PATRON_LOGO_3" ofType:#"mp4"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *playerCtrl = [[MPMoviePlayerController alloc]initWithContentURL:movieURL];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setTransform:CGAffineTransformMakeRotation(M_PI/2)];
playerCtrl.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:playerCtrl.view];
[playerCtrl play];
i think it works fine , this is for landscape mode for portrait we have to set frame according to portrait frame like..
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
after that we have to set to center of view.

UIImagePickerController has a black bar at the bottom by default?

I have an simple UIImagePickerController where I hide the camera controls and set the sourceType to the camera. This opens the live camera preview right away but there's about a 50px hight black bar at the bottom of the viewer. Any idea how to get rid of this?
Thanks Usman for the link. The ratio seems to be a bit different from what's suggested in the blog. The ratio of 1.23 works for iPhone 4 and 4s. Also, in order to preserve the aspect ratio, I suggest scaling both x and y.
picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = NO;
picker.showsCameraControls = NO;
CGAffineTransform cameraTransform = CGAffineTransformMakeScale(1.23, 1.23);
picker.cameraViewTransform = cameraTransform;
I believe this is due to the differing aspect ratio of the camera vs. the iPhone screen.