Reputation: 4100
I have a UIImagePickerController added to my view in this way:
- (IBAction)TakeCameraShot:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
// Given by default your orientation is in landscaperight already
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
/* picker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
picker.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;*/
[self presentViewController:picker animated:YES completion:nil];
/* picker.view.layer.cornerRadius = 150;
picker.view.clipsToBounds = YES;
picker.view.frame = CGRectMake(12, 60, 296, 290);*/
}else{
NSLog(@"Camera is not available");
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Important message" message:@"Unfortunately the camera is not available on your device." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert1 show];
}
}
I am trying to prevent it from being rotated to landscape with this code
// Given by default your orientation is in landscaperight already
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
The answer of stack overflow provided also said that it would only work if the UIviewController was already set to portrait only, so this is what I did from the general app settings (where you choose ipad, iphone, or universal). But this does not work.
Upvotes: 1
Views: 1736
Reputation: 492
just create a category for UIImagePickerController and put this line of code in that class
Upvotes: 0
Reputation: 1523
This Code will work on Ipad i used it but you need to add this
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
After presenting UIImagePickerController
too ---
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[self presentViewController:picker animated:YES completion:nil];
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
This will also going to work on ipod ,but on ipod it still gives you rotated image ,if you want a potrait image in ipod always , you need to change their orientation like this
UIImageOrientationRight -- This orientation is when image is clicked when camera is in potrait UIImageOrientationUp -- This when camera in landscape left
UIImageOrientationDown -- This is when camera is landscape right
UIImageOrientationLeft -- this is when camera is potraitupside down
now in all other three conditions other than first than change image orientation to UIImageOrientationRight .
This can be done by just checking orientation of coming image and apply new orientation .
Upvotes: 1