I have a landscape iPad app and I present a UIImagePickerController with sourcetype UIImagePickerControllerSourceTypeCamera to my active view controller modally. However, the live preview is in the wrong orientation and when I take a picture with the wrong orientation, it outputs an image with the correct orientation.
When I rotate the iPad, it fixes the orientation but it makes a thick black bar on one of the sides of the screen depending on the orientation (the camera overlay view isn't cut off by this black bar... only the preview is).
Everything was fine with iOS5, but iOS6 messed up the camera.
How do I fix this live preview orientation bug?
In order to fix the black screen at the bottom of the screen, you have to do a translation and scale, based on the device(iPad or iPhone).
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 25.0);
self.picker.cameraViewTransform = CGAffineTransformScale(translate, 480.0/380.0, 480.0/380.0);
self.picker.cameraOverlayView = self.view;
Try to change the scale values based on the device to make the black bar dissappear.
try this:
dispatch_async(dispatch_get_main_queue(), ^{
[self presentModalViewController:yourUIImagePickerControlle animated:YES];
});
Related
I am making an app that allows you to free draw ("annotate") over a background image of a music sheet. My app allows me to toggle the drawing to hide/unhide. When I rotate the orientation to landscape, the drawing and the background image do not align in the way that they did for portrait mode, so I would like to prevent orientation change when the drawing is not hidden and re-allow it if the drawing is hidden.
Is this possible? Any help would be much appreciated.
In your view controller do this:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ( drawingView.hidden )
return UIInterfaceOrientationMaskAll;
else
return [[UIApplication sharedApplication] statusBarOrientation];
}
UPDATED -- I have an iPad app that was originally designed and written for portrait mode only; I now want to add a UIScrollView so it will scroll in landscape mode. Auto Layout is checked and the different scenes are built using Storyboard. (I am following this tutorial). The major problem is when switching from portrait to landscape, the bounds of the frame change drastically, thereby causing problems with the logic of the scroll.
This is the image of the first scene (UIView) I am trying to add a UIScrollView to:
This is what it looks like in landscape mode (w/o scrolling):
This is my code in the -viewDidLoad method for that scene:
// create UIScrollView
UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.bookDetailView.frame.size.width, self.bookDetailView.frame.size.height)];
scroll.delegate = self;
scroll.pagingEnabled = YES;
scroll.scrollEnabled = YES;
scroll.showsVerticalScrollIndicator = YES;
CGSize scrollableSize = CGSizeMake(768, 1024); // size of portrait mode
scroll.contentSize = scrollableSize;
[self.view addSubview: scroll];
The scroll bar (as thin as it is) now shows, BUT although it moves like it should, the UIView doesn't move. Portrait mode works fine (no scrolling needed) but landscape mode doesn't scroll at all (even tho' the vertical scroll bar does move). I'm wondrering if I should abandon the idea of using scrolling for landscape mode and create separate scenes for landscape mode instead.
Is there any reason why you need a separate UIScrollView ? UITableView is already a scroll view. My guess is that the touch events from the UIScrollView you created are interfering with those of the UITableView.
In iOS 7, I am showing a UIBarButtonItem in the navigation bar of a UINavigationController. The UIBarButtonItem has an image for portrait orientation and another image for landscape orientation:
// "self" refers to the UINavigationController
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:portraitImage landscapeImagePhone:landscapeImage style:UIBarButtonItemStylePlain target:nil action:NULL];
If you just rotate the interface, the correct image is used for the interface orientation. However, if the view for the UINavigationController first appears in landscape orientation (say, by presenting it in landscape orientation or by dismissing a view controller that is covering it up in landscape orientation), the portrait image is used instead! Why is this happening? Is this a framework bug? If so, is there a way to work around this, so the landscape image will always be shown for landscape orientation?
I'm having this same problem.
I found a solution over at UIBarButtonItem with separate portrait and landscape images - layoutSubviews not called when popping a view controller from UINavigationController that sounded really promising, but it doesn't work for me. I'm going to go with changing the image on orientation change instead. Please post your solution if you find something better.
The landscape image works all of the time on UIToolbar, but not UINavigationBar. With UINavigationBar, I get the problem you state. I also had the problem that if I tapped the button in landscape, it would change to its portrait version.
Scenario
An app that captures an image from Front camera automatically after 3 sec countdown.
Everything is working as expected.
Code
//in viewDidLoad
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
self.imagePicker.delegate = self;
self.imagePicker.showsCameraControls = NO;
[self.imagePicker.view setFrame:kAppFrame];
[self.view addSubview:self.imagePicker.view];
[self.view bringSubviewToFront:self.imagePicker.view];
}
Problem
I have never told the ipad to use its rear device Still in certain cases the rear camera starts.
Steps to reproduce
Hold the camera in Landscape orientation
Click a photo (Will take you to next screen, pushed in Nav controller)
In the next screen tilt the ipad halfway towards face up orientation
Comeback to camera screen and you see it using rear camera.
This is a very strange behavior I am not even able to understand its cause.
check your code the line self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront; define that you open your front vamera of device.
Now your second problem: i am not sure but you have to rotate your image 90 degree. It's may be when you get image it's get in portrait mode.
It looks like I have found the solution.
just moving the entire code to viewWillAppear from viewDidLoad method.
It looked like I was relying a lot on view before it appeared with a certain orientation. Putting the code in viewWillAppear guaranteed me that the view is actually ready with its orientation set. I can now put anything on it.
I know this is not the proper answer but this is what I made out of the scenario. Any modifications/correction are most welcome.
At the moment I have an UIImageView inside a window. When the scene loads I save its position with:
imageView.center
The user can drag it around. On some occasions the item gets animated back to its original position which has been saved. This all works fine, when I hold the IPad vertically.
When I hold it horizontally though I cant move it back to that position, because in landscape mode I cant use the position which was saved in vertical orientation mode. this is because in Interface Builder I set the item to get auto sized relative to the borders (meaning if the item was in the center, then rotating the IPad it still stays in center)
So my question is: How can I get the correct original position the item would have in landscape orientation?
I tried to calculate the position by hand like this:
- (CGPoint)getHorizontalCoordinatesForPoint:(CGPoint)point
{
CGSize size = [[UIScreen mainScreen]applicationFrame].size;
CGFloat relativeX = (point.x / (size.width));
CGFloat relativeY = point.y / (size.height);
CGFloat horizontalScreenX = relativeX * (size.height);
CGFloat horizontalScreenY = relativeY * (size.width);
return CGPointMake(horizontalScreenX, horizontalScreenY);
}
but this position is a bit off. I think it is because I dont take into account the size of the navigation bar. Is there some converting function in ios which already does what I want?
Don't.
Rather, instead of saving [imageView center] when the scene loads, save it at key points:
-touchesBegan:withEvent: (or, if you are using gesture recognizers, in the gesture recognizer callback).
-didRotateFromInterfaceOrientation:
The minor complication is what happens if a user, say, is working in landscape, quits the app, rotates the portrait, and relaunches the app. In this case I would start the app in landscape and let the autorotation to portrait kick in and correct your center point.