I have an app where i'm making a UIView to take and upload images. My app is portrait only, has been for years, configured with "supported interface orientations" in my info.plist.
My problem is this, and it only happens on my iPhone 11 on IOS 13, NOT on my iphone7 running ios12.
My view is showing in portrait, like my views always do.
I have a button that opens up a UIPickerViewController like this:
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:true completion:nil];
If i then turn the camera to landscape, then take a picture OR press cancel, my UIView that previously was in portrait is now in landscape! It obviously looks super strange.
As soon as i put it in portrait, it pops back firmly in place.
Again, it only seems to happen on IOS13, but i have no idea how to solve it.
I have tried overriding shouldAutorotateToInterfaceOrientation in my UIView, it didn't help.
See below for screenshot of how it looks after the camera has rotated it.
Anybody have any thoughts?? Pointers much appreciated.
Custom a viewcontroller inherited UIImagePickerController, and overriding shouldAutorotate.
Try to use this class:
class CustomUIImagePickerController: UIImagePickerController {
override var shouldAutorotate: Bool {
return false
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}
Related
I have wrong UI orientation on UIImagePickerController when entering camera first time on iPad. Device in landscape but UIImagePickerController in portrait.
That how it's looks like
After device rotation everything is ok - UIImagePickerController gets correct UI orientation.
I have
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
and
- (BOOL)shouldAutorotate {
return YES;
}
Ok, I found an answer.
The presenting controller(UIViewController) has a property called modalPresentationStyle and it was set as UIModalPresentationFullScreen.
To resolve my problem I just set it as UIModalPresentationOverFullScreen.
presentingController.modalPresentationStyle = UIModalPresentationOverFullScreen;
Thats all.
I am using a regular UIImagePickerController to capture photo using the device camera. Following is the code I am using to create the UIImagePickerController,
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.imagePickerController.delegate = self;
and following is the code that I am using to display the UIImagePickerController
[self presentViewController:self.imagePickerController animated:YES completion:nil];
Now, when the UIImagePickerController is presented, if I zoom to capture and come back to my presenting view controller, the app crashes irregularly with BAD_ACCESS. After editing the scheme and some debugging, I see the following error,
-[PLImagePickerCameraView didHideZoomSlider:]: message sent to deallocated instance 0x140109400
It seems that the zoom slider delegate is called on an unallocated instance. Anyone else observed this behaviour? I am using working on iOS 8.1 and testing it on iPhone 5S. The search for PLImagePickerCameraView doesn't yield much. Any insights would be really helpful before I decide to go with custom Picker.
I experienced the UIImagePickerController zoom crash, as well. Adding a delay fixed most, but not all, of the crashes.
The root cause is the controller attempting to callback to a delegate after the delegate has been deallocated. I ended up implementing a subclassed UIImagePickerController to remove the delegate of the slider view.
You can find some sample code I posted on a similar question.
Problem
It looks like either the UITableView insets/frame is wrong.
The first cell is partially hidden by the navigation controller.
Notice that I would like to avoid subclassing UIImagePickerController as Apple documentation states that:
This class is intended to be used as-is and does not support subclassing
Screenshot
Configuration
OS: iOS 7.1
Device: iPhone 4s (not simulator)
Code
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(__bridge NSString *)kUTTypeMovie, nil];
imagePicker.delegate = self;
[imagePicker setVideoQuality:UIImagePickerControllerQualityType640x480];
[self presentViewController:imagePicker animated:true completion:nil];
Fix Attempts That Failed
I've tried to make sure that insets are automatically managed:
imagePicker.automaticallyAdjustsScrollViewInsets = YES;
I've tried to verify that the VC is aware of the navigation bar:
imagePicker.navigationBarHidden = NO;
The following fixes the issue but I'd like the navigation bar to remain translucent:
[imagePicker.navigationBar setTranslucent:NO];
This will happen with tableview, when you are scrolling tableview this is a normal behaviour. If you want it to properly align you can use the tableview method to do that
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:topRowValue inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
You will need to have the delegate of the tableview set to self and when the tableview has done scrolling, check which cell is on top and align it to the top using the above method. However, this will not guarantee the results as you desire. The reason for that is, you have different screen sizes for iphone4 and iphone5, say you have 5 cells that are visible in iphone5, in iphon4 it can happen that you see 4 cells completely and a part of the 5th cell in, as you are seeing now. So, if it isn't absolutely necessary, you can leave it as is.
self.tableview.automaticallyAdjustsScrollViewInsets = YES; try this.
You can get access to this table view by conforming your class to protocol UINavigationControllerDelegate
extension YourController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
guard let photosTableView = viewController.view.subviews[0] as? UITableView else { return }
}
}
You can do it using Storyboard as Follows...
1- Select your controller on storyboard
2- go to attribute inspector.
3- Uncheck "Adjust Scroll View view insets".
I am seeing an issue that only happens on IOS 7 and not IOS 6, i.e. the same code works on 6 but not 7.
Basically, there is this view that I need to transition to that must be in portrait mode.
So, like many of the other examples I found on StackOverflow, the way to force an orientation would be to call this on the navigation controller :
UIViewController *mvc = [[UIViewController alloc] init];
[self presentViewController:mvc animated:NO completion:^{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"Cleared");
[mvc.view removeFromSuperview];
[mvc removeFromParentViewController];
}];
}];
And in the target controller, I have:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
However, once I transition to this target UIViewController, nothing on that UIViewController becomes tappable at all. I am very sure that the UIButtons are linked properly because if I just load up this controller as the first controller when the app starts, the buttons all worked fine, but if I have to force an orientation on it before showing it, then the buttons don't work
I was wondering if anyone else has encountered such an issue in IOS 7 as well? This works perfectly in IOS 6
Thanks
IS
I'm having a very strange behavior:
in iOS 5 I present UIImagePickerController in this way:
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:imagePicker animated:YES];
now in iOS 6 this produce a crash. I resolved the crash by writing a category on UIImagePickerController:
#implementation UIImagePickerController (NonRotating)
- (BOOL)shouldAutorotate
{
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
#end
The problem is that now the UIImagePickerController doesn't rotate and it's shown up-side. Moreover, when I press the "cancel" button and the picker is dismissed, the app crash again.
If I use the UIImagePickerController inside a UIPopoverController, all works fine (belonging to the fact that the popover doesn't rotate) but when I dismiss the popover ALL view controller in my app stop responding to rotation events and this cause that all app is blocked in this orientation. To restore the correct behavior I need to quit the app from the background and open again.
This is the code I'm using to display popover
_cameraPopoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[_cameraPopoverController presentPopoverFromRect:_takeFromCamera.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
This problem drive me crazy !
What is your picker source type?
Photo library/album or camera roll?
Assuming that you are using Photo Library / Album source, on iPad, you MUST use a popover:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html (look in the overview, point 4)
presenting it fullscreen is not supported.
About the other issue (after dismissing the popOver, the other VC's stops rotating) check that you have a STRONG reference to your popover (strong property).
Paste the code you are using to present the popover.
While I don't recommend using the category to override the image picker's default behavior, there is a bug in the implementation that causes the crash mentioned:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
~~~~
}
The return value shouldn't be an orientation mask, it should be an orientation, e.g. UIInterfaceOrientationPortrait.