I'm developing a universal app.
The overall design is to have tab bars on iPhones, but not on iPads.
I've been trying to use size class, but found no luck.
Some example apps are MLB At bat and EBates, they have tab bars on the iPhone version but not on the iPad one.
How should I achieve this?
To hide tab bar in a specific iPad view(s). In your viewdidload method.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.tabBarController.tabBar.hidden=YES;
}
You could create a custom class of UIViewController and put this method in if you have many or a mixture of controllers that require this behaviour. You don't mention the specific behaviour you require
or
In your in your navigation controller (if you're creating one) use myController.hidesBottomBarWhenPushed = YES. If you're creating one in your AppDelegate for instance it would hide the tabbar throughout the views that are in the hierarchy of the navigationController (any view unless you use another navigationController in your app)
MyController *myController = [[MyController alloc]init];
// Hide tab bar for all app
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
myController.hidesBottomBarWhenPushed = YES;
}
[self.navigationController pushViewController:myController animated:YES];
You could always subclass your navigationController to achieve the same if you're using interface builder to achieve the same behaviour
You have not stated what language you're using Objective C or swift. Tagging your question with the language would be useful. The auto layout tag is irrelevant as this is nothing to do with autolayout
Related
I have a UIViewController. A button on the UIView should bring the user to a UISplitViewController. I'm using a segue for that, setup using the storyboard UI.
While some answers here seem to suggest this might not work (UISplitViewController has to be the root - or does this mean something different?), this does indeed work. Except - The SplitViewController on iPhone always starts with its DetailView, not with the MasterView.
What can be done about that?
As far as I know you cannot use splitViewControllers with iPhones, so you will have to use separate code to handle the iPhone version of your app(unless they have released something recently enabling this).
You could say
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
// Show your master view
} else {
// Present normally
}
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)...
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
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??
I have a reasonably simple split view application adapted from iPhone code. The main functionality is in shared classes with iPhone and iPad specific classes inheriting and augmenting the code. All the classes used in the iPad app have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
The main view controller consists of a UIToolbar and a UITableView. The responds to rotations correctly at every stage bar two. If I present a modal dialog from this view:
navigationController = [[UINavigationController alloc] initWithRootViewController:tvc];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navigationController animated:NO];
Everything works as expected including rotating the device until I dismiss the dialog in any way with:
[self dismissModalViewControllerAnimated:YES];
At which point my main view rotates 90 degrees. I've looked into the settings in nib files and it all seems to be fine. Any advice? A modal dialog presented by the UITableView on the left hand side does not present this problem.
Bonus Question:
I've discovered the modal dialog presented by the left hand view does have a glitch. But only one. If it is presented by the popover view in portrait mode and the device is rotated you get a rather impressive graphical glitch as it rotates out of the view for ever!
As noted in the comment above I managed to merge the two view controllers into one, incorporating the code to handle the toolbar + splitview controller into the iPad version. Originally there was a common class which inherited from UITableViewController, both the iPad and iPhone versions of the code inherited from this common class.
The problem was on the iPad I wanted a toolbar at the top and had to support the splitview controller too. This was problematic given that the class was a UITableViewController so I created a parent class containing the toolbar and the tableview controller plus the splitview code.
In refactoring I changed the common class to a UIViewController and made the changes to support a UITableView in code, as normal and instructed in several iPhone dev books. In the iPhone version of class I manually create the UITableView with the necessary methods. In the iPad version it comes from a xib file.
This schematically simplifies things as now the main view doesn't have a controller within a controller. It also solves the problem. The UI rotating 90 degrees upon closing a modal dialog no longer occurs.