1

I try to use UIImagePickerController to pick photo from iphone galery. On button click I do the following:

- (IBAction)attachAction:(id)sender {

    self.imagePicker = [[UIImagePickerController alloc] init];
    self.imagePicker.delegate = self;
    self.imagePicker.allowsEditing = YES;
    self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:self.imagePicker animated:YES];
}

In portrait it's fine, but when I rotate to landscape, present image picker and after doing some work dismiss it, layout of parent view controller breaks and I see half of screen with parent view and other half - black rectangle.

Any ideas how to solve this? How to force uiviewcontroller to change layout or its orientation manually after imagePicker dismissed?

I try to handle rotation by this code, but nothing changes situation

    - (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

    - (BOOL)shouldAutorotate
{
    return YES;
}

    -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self.view setNeedsLayout];
}
Doro
  • 2,413
  • 2
  • 14
  • 26

3 Answers3

0

It happens if you rotate the modalView, when the presenting controller does not handle rotation.

Try to add

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait; 
}

in this class, it should replace correctly the view when the modalview is dismissed

KIDdAe
  • 2,714
  • 2
  • 22
  • 29
  • Nothing happens, layout still broken – Doro Oct 15 '13 at 11:09
  • How are you handling rotation in this controller ? Could you share this part of the code please ? – KIDdAe Oct 15 '13 at 11:10
  • i added this method to handle rotation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } but this method do not fire – Doro Oct 15 '13 at 11:15
  • shouldAutorotateToInterfaceOrientation: is meant to be used prior to iOS6, since iOS6 there is -(NSUInteger)supportedInterfaceOrientation and -(BOOL)shouldAutorotate – hybridcattt Oct 15 '13 at 11:26
  • i found strange behavior: supportedInterfaceOrientations method was called only once, when VC was created and no more time, even when I rotate device. – Doro Oct 15 '13 at 14:36
0

Well, UIImagePickerController supports portrait mode only. But you need to use below property for forcing to landscape behaviour. @property (nonatomic, retain) UIView *cameraOverlayView Discussion You can use an overlay view to present a custom view hierarchy on top of the default image picker interface. The image picker layers your custom overlay view on top of the other image picker views and positions it relative to the screen coordinates. If you have the default camera controls set to be visible, incorporate transparency into your view, or position it to avoid obscuring the underlying content.

Also you can follow this link Force landscape orientation in UIImagePickerController

Community
  • 1
  • 1
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • I have source Type UIImagePickerControllerSourceTypePhotoLibrary, so i can't use this property, or I understood something wrong? – Doro Oct 15 '13 at 11:48
0

I found found problem. I have UITabBarController before this VC, and i forgot to implement

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

Subclassing UITabBarController and adding those methods solved problem. Thanks for advices!

Doro
  • 2,413
  • 2
  • 14
  • 26