PresentViewController without fullscreen - ios

Quick question again. When I use presentViewController to present a new viewcontroller on top of my current one it is full screen. How do I get it to present a specific size? Or should I use another method.
Code:
- (IBAction)showProfile:(id)sender {
ProfileView *profileTop = [[ProfileView alloc] init];
profileTop.delegate = self;
[self presentViewController:profileTop animated:YES completion:nil];
}

If you are developing an app for iPad then you can make use of viewController's modalPresentationStyle property, You need to set for presenting viewController.
It has 4 values for that variable.
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet,
UIModalPresentationFormSheet,
UIModalPresentationCurrentContext
You can select which one suites you the best.

I'd suggest doing a little more research, specifically in Apple's reference. Of note, there is this quote from the View Controller Programming Guide (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html):
Presentation Styles for Modal Views
For iPad apps, you can present content using several different styles. In iPhone apps, presented views always cover the visible portion of the window, but when running on an iPad, view controllers use the value in their modalPresentationStyle property to determine their appearance when presented. Different options for this property allow you to present the view controller so that it fills all or only part of the screen.
And specifically, on the API reference page for presentViewController (http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/presentViewController:animated:completion:):
On iPhone and iPod touch, the presented view is always full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.
Only the iPad appears to have any support for non-fullscreen modals.

On iPad you can just use:
[viewcontroller setModalPresentationStyle:UIModalPresentationFormSheet];
example:
LoginDialogViewController * login_dialog = [[LoginDialogViewController alloc] init];
[login_dialog setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:login_dialog animated:true completion:nil];

You can use the same code. Then adjust the view size in the xib file. See the below figure

Related

How to get reference to UIPopoverController when using adaptive segue?

In my iOS 7 app, I detected if a segue was a popover via this check in prepareForSegue:
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]])
But now that I am using adaptive segues, the Present as Popover segue is no longer returning true in the above check. This is because segue is no longer a UIStoryboardPopoverSegue, instead it is a UIStoryboardPopoverPresentationSegue. However, one cannot simply add the Presentation word because that's not defined.
What is the appropriate way to detect when the segue is a popover from an adaptive segue, as opposed to a full screen modal presentation?
And, how do you get a reference to the popover for iOS 8? The following is what I'm doing for iOS 7 but again because it's not a UIStoryboardPopoverSegue this will cause a crash.
UIPopoverController *popover = ((UIStoryboardPopoverSegue *)segue).popoverController;
popover.popoverContentSize = CGSizeMake(380, 1000);
There actually was no need to get a reference to the popover for iOS 8. You can access the popoverPresentationController directly in the view controller that's presented. Then use dismissViewControllerAnimated to dismiss the view controller. You can set the popover content size directly in the view controller that's being presented via preferredContentSize. I found I had no need to obtain a reference in prepareForSegue, at least when running on iOS 8. iOS 7 is a different story.
Elaborating on Joey's answer, which led me to what seems the new manner of achieving what we used to do with UIPopoverController.
This code in prepareForSegue:Sender:
UIViewController *destination = segue.destinationViewController;
UIPopoverPresentationController *ppc = destination.popoverPresentationController;
ppc.delegate = self;
is a simple way to successfully set your view controller as delegate of a UIPopoverPresentationController much the same as you are probably used to doing with the old UIPopoverController.
And, of course, while you are at it you'll probably add:
[destination setPreferredContentSize:CGSizeMake(300.00f, 300.00f)];
if you were in the habit of setting UIPopoverController size here as well.
This may not be the most foolproof way to do it but you could check the popoverPresentationController property on your destination view controller. From there you can configure the popover anchor and such.
Check the "Configuring a Popover for Display" section of the UIPopoverPresentationController doc. (Not sure if we're allow to link to them at this point, are we?)
Note too that now we're talking about UIPopover*Presentation*Controllers, not UIPopoverControllers. It's a little confusing...

What is the large popup view in UIKit called?

I am writing an iPhone application where I want to utilize the large popup view, but I don't know what it's called. I have a picure on it.
I mean the middle square that isn't shadowed. It has the title "Köp mer utrymme". I know it's from an iPad, but I'm pretty sure a similiar one exists on the iPhone, for example, the iTunes-store agreements. I looked in Apple's UIKit User Interface Catalog, but I couldn't found it there.
Does anyone know what it's called or how to get it?
On iPad it could be a UIPopoverController with a custom view controller inside it, or a modally presented view controller. You can't use that on iPhone (at least not in the same way, popovers don't exist and modal views are full screen).
On iPhone you could use a UIAlertView, or you could search github / cocoacontrols for a suitable 3rd party implementation.
The view on the picture is presented modally. When presenting a view modally, you can customize the presentstion style. The default style is UIModalPresentationFullscreen, but the style in the picture is UIModalPresentationFormSheet.
To present a view controller in that style, you first create an instance of the view controller and then set its style.
MyViewController *vc = [[MyViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:vc animated:YES completion:nil];
Note that isn't possible to change the presentation style for iPhone. (I must have imagined that the iTunes-store agreement wasn't fullscreen.)
Use KGModal.h and KGModal.m class. For a PopVieController is is best ....and easy to make and add control over it and no need to set frame for orientation ....
Find these 2 Class (KGModal.h and KGModal.m)...

presentViewController working in iOS 6 but not displaying the view in iOS 5

I started developing my app for iOS 6 and got it working there, now I am having to make sure it also supports iOS 5.1 so it will work on the iPad 1. The port was pretty easy, though only supporting landscape orientation is more of a pain in iOS 5 compared to how easy it is in 6. I'm left with one issue that I can't resolve.
I have the starting screen layout shown below and then when you press the 'Perform' button it should present another view controller modally, full screen. This is the code that the perform button calls in the parent view controller.
- (void)performButtonPressed:(UIImage *)notationImage {
self.performViewController = [[YHPerformViewController alloc] initWithImage:notationImage
recordingService:self.performanceRecordingService];
self.performViewController.modalPresentationStyle = UIModalPresentationFullScreen;
self.performViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:self.performViewController animated:YES completion:^{
[self.performViewController startPerformance];
}];
}
In iOS 6 this is fine. In iOS 5 all the right code seems to be called:
loadView on the view controller being presented
shouldAutorotateToInterfaceOrientation - to which I return YES
my 'startPerformance' method is called and does its things
However the view doesn't actually appear on screen and all the views associated with view controllers higher up the hierarchy stay on screen (the shapes at the top and the navigation control). Only the view for the current view controller is faded out. Even weirder is that during the transition this view is rotated 90 degrees as it is fading out. I've included a screen capture below. If I change the modalPresentationStyle to UIModalPresentationFormSheet it kind of works apart from the expected issue of my full sized view not fitting.
Any thoughts?
Starting layout:
Weird rotation of subview during transition. Also the whole screen should be fading out, not just one view:
What was expected to happen and does in iOS 6.
I have come up with a hack that solves this problem. But I would love to find a real solution.
My bodged solution is to change the modalPresentationStyle to UIModalPresentationFormSheet. Then use a variation on the hack described in How to resize a UIModalPresentationFormSheet? to get the form sheet to be the desired size.
- (void)performButtonPressed:(UIImage *)notationImage {
self.performViewController = [[YHPerformViewController alloc] initWithImage:notationImage
recordingService:self.performanceRecordingService];
// This is a bit of a hack. We really want a full screen presentation, but this isn't working under iOS 5.
// Therefore we are using a form sheet presentation and then forcing it to the right size.
self.performViewController.modalPresentationStyle = UIModalPresentationFormSheet;
self.performViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:self.performViewController animated:YES completion:^{
[self.performViewController startPerformance];
}];
self.performViewController.view.superview.bounds = self.performViewController.preferredBounds;
}
This requires the view controller being presented to a 'preferredBounds' property and to have this in its loadView method.
- (void)loadView {
… // Usual loadView contents
// Part of the hack to have this view display sized correctly when it is presented as a form sheet
self.preferredBounds = self.view.bounds;
}
[self presentViewController:self.performViewController animated:YES completion:nil] works in iOS 6+ versions only.
You have to use [self presentModalViewController:controller animated:YES]; in

XCode: MasterDetailsView - DetailsView without Splitscreen in Landscape?

actually I'm quite new with Xcode and couldn't find the answer to the following two questions by a google search:
to make it short: I'm working on an iPad app that displays proposals. For this purpose you should choose a proposal from the table in MasterView and then see the details in the DetailsView in landscape mode (but without the MasterView on the Spitscreen).
So when the app starts in landscape mode, I wanna see directly the first proposal full screen on the DetailsView. And when I tap onto the screen the MasterView should popup/unhide with the other proposals in the table. Is this possible?
I wanna display the PDFs in a WebView like in iBooks. That means that the navigation bar is hidden and only when I tap onto the screen the navigation bar should appear at the top of the screen.
I'm kind of sure this questions have been solved somewhere but I couldn't find anything by search so I hope you can help me anyway :-)
Thanks in Advance!
Q1: Use can use one of many methods to present a view (look up under Apple's doc on UIViewController under "Presenting Another View Controller's Content" heading). Two that I have used are: – presentModalViewController:animated: and – presentViewController:animated:completion: (the latter is the latest addition in iOS 5.0)
So let's say you have a detail controller called MyDetailViewController, in your Master View Controller's implementation file (the .m file), under viewDidLoad method, you would do some thing like this to present it as a full screen view.
MyDetailViewController *myDetailViewController = [[MyDetailViewController alloc] initWithNibName:#"MyDetailViewController" bundle:nil];
[myDetailViewController.view setFrame:CGRectMake(0, 0, 1024, 768)]; //might not need this
[self presentViewController:newDetailViewController animated:YES completion:^{
NSLog(#"complete"); //optional
} ];
To dismiss or hide this MyDetailViewController with a tap or touch, you can use UITapGestureRecognizer or touchesEnded method and using one of the dismiss methods (refer back to Apple's UIViewController again for this).
Q2: I personally have not used UIWebView to display PDF and not sure if iBooks is using UIWebview to do it. But to display a varieties of popular documents formats, you can use either the QLPreviewController class or UIDocumentInteractionController. You can hide the toolbar while the document is displayed.
Good luck.

Ipad orientation is not working well

I am creating an application with Landscape Right orientation. For that I set the Initial interface orientation property in info.plist file. Then in every view I handled
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return(interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
It works fine in simulator but in device its behave differently.
My first view is in proper orientation. There is is popover which display another view that comes in portrait mode. Still my status bar is in Landscape Right..
For navigating from one view to another view I am using..
self.window.rootViewController = self.myNav;
I have multiple navigation Controller and adding those using the upper code.
I am not getting what is the problem.
Any help will be appreciated.
EDIT: I had used
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
I never get this issue in simulator but getting this in device and not every time. I have used Supported interface orientations (iPad) too and set Landscape (right home button) value for item0.
Thanks In advance
You need to set the "Simulated Metrics > Orientation" property of your top view (in all your xib files) to be "Landscape". The default is portrait.
The question was answered pretty well here - Landscape Mode ONLY for iPhone or iPad .
I also have an app that like yours only supports UIInterfaceOrientationLandscapeRight. I haven't run into any orientation issues so far. I only have one UIViewController under the window. This UIViewController has its own UITabBar that I use to change pages. So, we change pages differently. I set my UIViewController using the rootViewController property of the window just like you, but again I only have one.
Also, I never had to do anything like the [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] call that you included. Since you only support LandscapeRight orientation, you shouldn't care to be notified of changes.
EDIT
I created a sample project, which I can post if necessary, and I think I may know your problem. First - do you only encounter the sizing issue inside popovers? If so, then I don't think orientation is throwing you off but the popover itself. My sample project has 3 view controllers. The first loads the second by changing the window's rootViewController. That worked fine. The second view controller has a button to open a popover. This will show up wrong unless you set the contentSizeForPopover on the view controller as shown below:
- (IBAction) showVC3InPopover
{
UIViewController * vc3 = [[VC3 alloc] init];
/** Set the contentSizeForViewInPopover property to determine how
large the view will be in the popover! You can do this in the
init method(s) of the view controller if you prefer, it's just
easy to do here */
vc3.contentSizeForViewInPopover = vc3.view.frame.size;
[_popover release], _popover = nil;
_popover = [[UIPopoverController alloc] initWithContentViewController:vc3];
[vc3 release];
[_popover presentPopoverFromRect:_showPopoverButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
See if this fixes your problem. If it does, there are other ways to control the popover size, but this is just what I typically do. However, just know that the PopoverController ignores the size of the view in the viewcontroller you load.
How many views (or viewControllers) you have? You might need to implement this orientation logic in all those views??

Resources