Does imagepicker have to be a popover on an iPad - ipad

It appears that different documents and discussions indicate that a uiimagepicker should be presented inside a popover, when on an iPad.
Is this really the case or just a suggestion.
I ask as it seems to run perfectly fine in the same VC as the iPhone.
Thanks,
Guy

You can create a UIImagePickerController and add it's View as a subview on any View you like
For example you can add it to a UIViewController
UIImagePickerController imagePicker = new UIImagePickerController();
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
View.AddSubview(imagePicker.View);

Related

Container View Controller disappears when Child View Controller presents a Modal View Controller iOS Swift

I'm new to the iOS swift scene and i was hoping you would be able to help me find a solution or send me on an alternative route to achieving this.
Here is the diagram to my Application Interface Structure
So, i have the ContainerVC which has a UIScrollView, and that UIScrollView has a the four ChildVCs inside. My problem is when i present the ModalVC from one of the ChildVCs, the ContainerVC, which has the UIScrollView
and the application's background disappears from the screen completely and the background of the app becomes black. I believe that happens because iOS thinks that the ContainerVC is no longer being used so it removes it from the hierarchy when the modal is presented on top of the ChildVC.
I wanted to be able to have the ContainerVC, which provides a background for the app and the UIScrollView where the ChildVC are embedded, visible at all times even when a ChildVC presents the ModalVC modally. Before the ModalVC is presented, the ContainerVC can be seen behind the ChildVC around the edges (modal ahah) of the screen and everything is fine, but that changes when i trigger a tap event and i present the modal. Here is the before and after:
Before Tap Event >>>
After Tap Event & ModalVC appears
You can see that the purple background disappeared now that the ModalVC is presented and though you cant see it, I'm not able to scroll side ways anymore because the UIScrollView isn't there either.
How can i present the ModalVC from the ChildVC without losing the ContainerVC and its UIScrollView inside? i.e. from disappearing and staying the the view hierarchy
Here is the code is use to present the ModalVC from a given ChildVC.
func didTapCell(origin: String) {
let modalVC = storyboard?.instantiateViewController(withIdentifier: "overlayModal") as! OverlayModalViewController
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = self // i think this self has something to do with the background disappearing
modalVC.modalPresentationStyle = .overCurrentContext
self.present(modalVC, animated: true, completion: nil)
}
I have been looking for a solution for a while now but i can't seem the figure it out. I would be great if you could help work this out or help find a way around it and achieving the same. Please help me out.
Thank you in advance. Please let me know if there's anything i can do to clarify anything.

Crash on presenting UIImageViewController at iPad in Landscape mode

I have an iPad app that should works only at Landscape mode.
But I have to show UIImagePickerController.
According to documentation UIImageController works only with Portrait mode.
If I disabple Portrait orientation and present UIImageViewController I receive crash with
"Supported orientations has no common orientation with the
application, and [PUUIAlbumListViewController shouldAutorotate]”
How I can configure project to disable Portrait mode at iPad and allow to show UIImagePickerController?
My solution without setting Portrait mode
let imagePicker = UIImagePickerController()
imagePicker.modalPresentationStyle = .popover
imagePicker.popoverPresentationController?.sourceView = self.view
imagePicker.sourceType = (UIImagePickerController.isSourceTypeAvailable(.camera)) ? .camera : .photoLibrary
imagePicker.delegate = self
You have no choice. As you have already said, the solution is to enable portrait orientation in your app.
If the intersection between what the view controller requires and what the app permits is null, the app will crash (as you have seen).

Swift Modal View Controller with transparent background [duplicate]

This question already has answers here:
Transparent background for modally presented viewcontroller
(5 answers)
Closed 7 years ago.
I know this topic is quite popular, but I'm a little iniciate problem in a programming language, the fact is that I still do not understand where I put the code. Well, I'll tell the whole case:
I'm trying to make a modal Swift in a little different from normal: By clicking on a button, the ViewController is displayed (following modal type) on the screen, but with transparent background. Only the blue View with label will be displayed. When this ViewController is presented, it is with transparent background, but as soon as it completes the transition, it will stay with the black background. Already deactivated the opaque option, and tested some options, but nothing this troubleshooting.
Some can help me?
The video is a test in the simulator on the case (https://www.youtube.com/watch?v=wT8Uwmq9yqY).
I'm starting with swift, and I'm still pretty lost with how to program in Xcode, I read an answer to a question that has the following code to solve this:
self.presentingViewController.providesPresentationContextTransitionStyle = YES;
self.presentingViewController.definesPresentationContext = YES;
modal.modalPresentationStyle = UIModalPresentationOverCurrentContext;
Where do I put this code?
You can do it like this:
In your main view controller:
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .overCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
In your modal view controller:
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
If you are working with a storyboard:
Just add a Storyboard Segue with Kind set to Present Modally to your modal view controller and on this view controller set the following values:
Background = Clear Color
Drawing = Uncheck the Opaque checkbox
Presentation = Over Current Context
As Crashalot pointed out in his comment: Make sure the segue only uses Default for both Presentation and Transition. Using Current Context for Presentation makes the modal turn black instead of remaining transparent.

Adding UIImagePickerController as a subview

I want to add a UIImagePickerController in a custom frame, so have been following a few posts around adding the UIImagePickerController view as a subview.
A couple of questions:
How would I adjust the frame of this subview?
After adding as a subview, touch seems to be disabled (I can't browse photos or press the cancel button), how would I solve this?
Many thanks in advance!
My Code:
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.delegate = self;
//This is a subview of self.view.
[self.pickerControllerHolderView addSubview:self.imagePicker.view];
// This seems to adjust the size of the view, but squashes the view.
// self.pickerControllerHolderView.transform = CGAffineTransformMakeScale(1, 0.5);
The internals of this class are private and it is not meant to be added as a subview. It is a self contained view controller and navigation controller and will most likely not work how you expect it to. If you need custom UI for picking photos, you should access the ALAssetsLibrary and display the contents yourself.

presentViewController black background instead of transparent

I have a view that I wish to present to the user in the standard way (sliding up from the bottom of the screen). About half this view is a transparent background and the bottom half has some input fields (imagine the way the keyboard pops up). When I call [self presentViewController] on the rootViewController, it slides the view up, but then about half a second later, where the view used to be transparent it is replaced with black instead. This happens with both presentViewController and presentModalViewController. How to change this behaviour?
This is possible, and rockybalboa provides a solution to this issue in the forum post on raywenderlich.com:
iOS 8 UIModalPresentationCurrentContext is not transparent?
That solution being, quoting balboa's answer, in Objective-C:
Before iOS 8, you do this:
[backgroundViewController setModalPresentationStyle:UIModalPresentationCurrentContext];
[backgroundViewController presentViewController:_myMoreAppsViewController animated:NO completion:nil];
in iOS 8, you have to do this:
backgroundViewController.providesPresentationContextTransitionStyle = YES;
backgroundController.definesPresentationContext = YES;
[overlayViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
To supplement the above code with the Swift equivalent:
backgroundViewController.providesPresentationContextTransitionStyle = true
backgroundController.definesPresentationContext = true
overlayViewController.modalPresentationStyle = .OverCurrentContext
Having implemented this using Xcode 6.3 beta 3 on iOS 8.1 with Swift 1.2, it works perfectly.
Just a comment that I viewed three different SO questions on this - the more recent now marked as duplicates - prior to finding and attempting the Ray Wenderlich forum solution.
As far as I know, transparent background is not supported when you presents a model view controller. Try retain the controller in your root view controller and simply add subview to the root view controller.
In the end, it looks like it's not possible for it to be transparent, I've got around this by adding this view as a subview outside of the bounds of the root view controller, and then slid it into place using an animation block. Not a lot of extra code, but it would have been nice to be able to use standard iOS behaviour to do it.
I had a similar problem with the black background appearing after a short delay when creating the controller with
Disclaimer *vc = [[Disclaimer alloc]init];
What solved the problem for me was to create a corresponding object in IB and instantiate the viewcontroller using it's storyboard ID:
Disclaimer *vc = (Disclaimer *)[self.storyboard instantiateViewControllerWithIdentifier:#"SBIDDisclaimer"];
[self presentViewController:vc animated:YES completion:nil];
I guess doing it via IB does some additional initialisations.
Using SWIFT 4, just add this code to the view controller you want to have a transparent background.
override func viewDidLoad()
{
super.viewDidLoad()
self.modalPresentationStyle = .overFullScreen
self.view.backgroundColor = UIColor.clear
}

Resources