presentModalViewController in UISplitViewControllers detailView not presenting the view in full screen - objective-c

I have added the UISplitViewController view in my mainViewControllers view, the code is below.
documentsRootViewController = [[DocumentsRootViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:documentsRootViewController];
documentsRootViewController.title = #"Document List";
documentDetailView = [[DocumentsDetailView alloc] initWithNibName:#"DocumentsDetailView" bundle:nil];
documentsRootViewController.detailViewController = documentDetailView;
docSplitViewController = [[UISplitViewController alloc] init];
docSplitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, documentDetailView, nil];
docSplitViewController.delegate = documentDetailView;
CGRect splitViewFrame = CGRectMake(0, 0, cetralArea.frame.size.width, cetralArea.frame.size.height);
docSplitViewController.view.frame = splitViewFrame;
[cetralArea addSubview:docSplitViewController.view];
now what I want is to present a ViewController from the DetailView of the UISplitViewController I am trying to do it as below inside the DetailViewControllers Click Me! buttons click.
- (IBAction) buttonClicked:(id)sender
{
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:#"pdf" inDirectory:nil];
NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file
ReaderDocument *readerDocument = [ReaderDocument withDocumentFilePath:filePath password:phrase];
if (readerDocument != nil) // Must have a valid ReaderDocument object in order to proceed with things
{
ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];
rViewController.delegate = self; // Set the ReaderViewController delegate to self
[self presentModalViewController:rViewController animated:NO];
}
}
but this is resulting in an awkward presentation
can anyone suggest what is the problem here, thanks in advance..

In your screenshots I can't really tell where is your split view controller left side and right side (detail view) located. Change background colors of the views to distinguish positions. Seems you are having problems with them.
Anyways, you can try presenting the modal view controller from the splitView instead of the Detail.
[splitViewController presentModalViewController:rViewController animated:NO];

I believe the trick here is changing the modalPresentationStyle (and optionally modalTransitionStyle) of the view controller that you want to display modally:
ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];
rViewController.delegate = self; // Set the ReaderViewController delegate to self
rViewController.modalPresentationStyle = UIModalPresentationFullScreen;
rViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:rViewController animated:YES completion:nil];

I had the same problem (in iOS 5.1). Set the modalPresentationStyle to UIModalPresentationPageSheet and it should work as expected.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
rViewController.modalPresentationStyle = UIModalPresentationPageSheet;
rViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}

What i found is you are giving splitview size like cetralArea.frame.size.width.
Instead of that simply give directly size that you want to give to the Splitview.
Hope it will work for you.

Related

Add button horizontally to Page Control

I need to add a button horizontally to a Page Control in UIPageViewController. I have added my pageviewcontroller as a subview to a ViewController, by default im getting the page control .Now I wanted to add a button, Can anyone suggest any way to add button ?
Thanks in advance!!
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
#"Main" bundle:[NSBundle mainBundle]];
UIViewController *p1 = [storyboard instantiateViewControllerWithIdentifier:#"First"];
UIViewController *p2 = [storyboard
instantiateViewControllerWithIdentifier:#"Second"];
UIViewController *p3 = [storyboard
instantiateViewControllerWithIdentifier:#"Third"];
UIViewController *p4 = [storyboard
instantiateViewControllerWithIdentifier:#"Fourth"];
_Array = #[p1,p2,p3,p4];
_pageViewController.dataSource = self;
_pageViewController.delegate = self;
[_pageViewController setViewControllers:#[_Array[0]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[_pageViewController willMoveToParentViewController:self];
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.view sendSubviewToBack:self.pageViewController.view];
[_pageViewController didMoveToParentViewController:self];
I believe this is what youre looking for. He explains in detail how to add the buttons "on top of " your page view controller view. You can do this after you add the page view controller, you can use the sendSubviewToBack method to ensure that the buttons remain in the foreground while you will be able to swipe between the different view controllers of your page view controller. Have a look here
you can extract the view where page control is kept on, then you can do what ever you want. Below is the code for extracing the pagecontrol view:
NSArray *subviews = self.pageController.view.subviews;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
self.pageControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
UIView *pageControlBaseView = [[UIView alloc] initWithFrame:CGRectMake(0,60,100, 40)];
[pageControlBaseView addSubview:self.pageControl];
self.pageControl.pageIndicatorTintColor = [UIColor redcolor];
self.pageControl.currentPageIndicatorTintColor = [UIColor greencolor];
[self.view addSubview:pageControlBaseView];
please let me know if you need more clarity.

UIPageViewController - view doesn't load

I want to load a UIView as the first page and some UIImageViews after that. The UIImageViews load fine, but the first UIView shows blank.
I designed the UIView in storyboard. It has some UIButtons and few other controls. What am I doing wrong?
I created the project from the default pageController template.
ModelController.m
- (id)init
{
self = [super init];
if (self) {
// Create the data model.
/*
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
_pageData = [[dateFormatter monthSymbols] copy];
*/
NSMutableArray *imageViews = [[NSMutableArray alloc] init];
FirstViewController *firstViewController = [[FirstViewController alloc] init];
firstViewController.view.frame = CGRectMake([UIScreen mainScreen].bounds.origin.x,[UIScreen mainScreen].bounds.origin.y,[[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
[imageViews addObject:firstViewController];
for (int i=1; i<=19; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"picture%i.jpg", i]]];
imageView.frame = CGRectMake([UIScreen mainScreen].bounds.origin.x,[UIScreen mainScreen].bounds.origin.y,[[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
[imageViews addObject:imageView];
}
_pageData = imageViews;
}
return self;
}
- (DataViewController *)viewControllerAtIndex:(NSUInteger)index storyboard:(UIStoryboard *)storyboard
{
// Return the data view controller for the given index.
if (([self.pageData count] == 0) || (index >= [self.pageData count])) {
return nil;
}
// Create a new view controller and pass suitable data.
DataViewController *dataViewController = [storyboard instantiateViewControllerWithIdentifier:#"DataViewController"];
dataViewController.dataObject = [self.pageData objectAtIndex:index];
if(index == 0)
{
//[dataViewController addChildViewController:[self.pageData objectAtIndex:index]];
FirstViewController *firstViewController = [self.pageData objectAtIndex:index];
[dataViewController.view addSubview:firstViewController.view];
}
else
{
UIImageView *imageView = [self.pageData objectAtIndex:index];
[dataViewController.view addSubview:imageView];
}
return dataViewController;
}
You haven't provided enough context to be certain, but it appears that what you need to load from the storyboard initially is an instance of FirstViewController, not an instance of UIView, so you'd need to do something like this instead of what you're currently doing:
FirstViewController *firstViewController = [self.storyboard instantiateInitialViewController];
// Note: If you need to adjust the frame of the controller's view, use the screen's
// application frame rather than its bounds.
controller.view.frame = [UIScreen mainScreen].applicationFrame;
Also, this seems like a bad idea, since you later fill the rest of the array with instances of UIImageView:
[imageViews addObject:firstViewController];
Why not add the controller's view to the array? Then you could eliminate the conditional logic in your viewControllerAtIndex:storyboard: method. Also, it's not clear why you're passing the storyboard in as an argument rather than using the built-in property, or for that matter, what class the code you posted belongs to, and what its relation is to the rest of your app. Maybe you could provide a little more info about that.
I got it to working by adding a xib file for FirstViewController. What ever I design in the xib shows up well. Previously I was designing it in the storyboard.

Changing size of UIImagePicker presented via UIPopOver (iPad)

I am trying to change the size of a UIImagePicker which I am presenting via a UIPopOver. The code is shown below. The issue is that the PopOver size doesn't display properly - it briefly flashes up in the correct size, then animates down to the usual default size.
Can anybody advise me on how I can change the size of the popover ?
- (void)showImagePickerForPhotoLibrary {
NSLog(#"Picker");
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
//popoverController.popoverContentSize = CGSizeMake(768, 1000);
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
}
}
else {
[app.mainViewController presentModalViewController:imagePickerController animated:YES];
}
}
I'm not sure this is the most elegant solution, however it seems to work fine for me:
You can embed the UIImagePickerController's view into a "container" UIViewController's view.
- (void)showImagePickerForPhotoLibrary {
NSLog(#"Picker");
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[imagePickerController.view setFrame:containerController.view.frame];
}
}
else {
[app.mainViewController presentModalViewController:containerController animated:YES];
}
}
Hope this helps
EDIT: for some strange reason, the frame does indeed change when in landscape right.
To come over this, you need to set the image picker's view's frame after you present the popover.
I have edited the code above to show this.
Also, in your controller, add this:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[imagePickerController.view setFrame:imagePickerController.view.superview.frame];
}
When I tried Mutix's solution the popover showed just the navigation bar with an empty white view.
My way around it was to add imagePickerController as a child of containerController and not just adding the picker's view.
Mainly it means to replace this line:
[containerController.view addSubview:imagePickerController.view];
with these lines:
[containerController addChildViewController:imagePickerController];
[containerController.view addSubview:imagePickerController.view];
[imagePickerController didMoveToParentViewController:containerController];
In addition, when using this approach, I didn't need any special handling for landscape mode.

Black Bar in UIImagePicker on iPad - Only in Landscape Right Orientation

I am showing a UIImagePicker (itself in a UIView) via a UIPopOver. This works fine, however when the iPad is rotated onto its right side I get a strange black bar along the left hand side of the popover as per the image below. The cancel button is also partially off the right hand of the screen. This doesn't happen in any other orientation which is odd.
The code is also listed below. Can anyone suggest why I am getting this black bar ?
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[imagePickerController.view setFrame:containerController.view.frame];
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[containerController release];
}
For some strange reason, the view's frame does change in landscape right.
To come over this, set the frame after you present the popover (view code below).
That should do the trick.
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[imagePickerController.view setFrame:containerController.view.frame];
[containerController release];
}
Also, in your controller, add this to reset the frames when the rotation occurs:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[imagePickerController.view setFrame:imagePickerController.view.superview.frame];
}
The above approach works with iOS 5 and above but on iOS 4 and prior it's not possible to add the UIImagePickerController as a subview and then show it. It always has to be presented as a ModalViewController.
Try this. Reposting one solution I found using [currentDevice endGeneratingDeviceOrientationNotifications]
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
// Display the camera.
[self presentModalViewController:picker animated:YES];
// Given by default your orientation is in landscape right already
while ([currentDevice isGeneratingDeviceOrientationNotifications])
[currentDevice endGeneratingDeviceOrientationNotifications];
Source: Disable rotation in UIImagePicker

ModalViewController loading on top of another Modal

There may be a better way to do this, and please direct me if there is.
I'm creating an UIImagePickerController with an overlayView in viewDidAppear for 'choose from library', 'take photo', 'flash' 'camera source', etc.
// Set up the camera
imagePicker = [[UIImagePickerController alloc]
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.cameraOverlayView = [self cameraOverlayView];
cameraOverlayView.backgroundColor = [UIColor clearColor];
imagePicker.showsCameraControls = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:imagePicker animated:YES];
I then have an IBAction that calls my 'choose from library function', loading another UIImagePickerController to choose a photo from the device.
- (IBAction)library:(id)sender
{
UIImagePickerController *libraryPicker = [[[UIImagePickerController alloc] init] autorelease];
libraryPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryPicker.delegate = self;
[self.imagePicker presentModalViewController:libraryPicker animated:YES];
}
I'm getting a white bar across the top about the size of a status bar when the 'choose from library' modal is presented. I know it has something to do with overlaying a modal on top of a modal, but I don't know how to solve it. (IE, my view layout for 'take photo' navigates fine, although doesn't display the additional 'choose from library' modal).
Any ideas? Any help or direction would be greatly appreciated!
Try
[self presentModalViewController:libraryPicker animated:YES];
Instead of
[self.imagePicker presentModalViewController:libraryPicker animated:YES];