How to change the height of tab bar in iPhone X - ios

I have an app which was previously designed in 2014. Now I have to make the app design compatible with iPhone X.
When i run the app on iPhone X simulator everything works fine except the tab bar. The tab bar height gets increased in iPhone X simulator.
I know the basic safe area guide thing but for now i don't to fill the
top and bottom empty areas, i just to display the standard tab bar as
it displays on the other iPhones.
The tab bar is added programmatically so i tried to change its height as following
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
self.tabBarController.viewControllers = [[NSArray alloc] initWithObjects:trailsNavController,mapNavController, gpsNavController,infoNavController, signUpNavController, nil];
self.tabBarController.delegate = self;
self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, self.tabBarController.tabBar.frame.origin.y, self.tabBarController.tabBar.frame.size.width, 40);
self.window.rootViewController = self.tabBarController;
The app design gets distorted when i add splash screen.
Any other way to change its height? Any help would be appreciated.

So far the only solution i know is Introducing auto layouts.

You should use proportional height. For example:
self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, self.tabBarController.tabBar.frame.origin.y, self.tabBarController.tabBar.frame.size.width, self.view.frame.size.height/6);

Related

How to move down the display of presentation view in iOS

I'm working on an iOS app which has a couple of non-modal views and a couple of modal views. The non-modal views have a navigation bar at the top, while the modal ones don't. The problem is that there's a common background image for both types. On the modal views, due to the lack of the navigation bar at the top, there's a small gap between the bottom of the image and the bottom of the display.
Here's the code for the opening of a non-modal display:
settingsController = [[SettingsController alloc] init];
settingsController.appState = appState;
[self.navigationController pushViewController:settingsController animated:YES];
[settingsController release];
Here's the code for the opening a modal display:
nextLevelViewController = [[[NextLevelViewController alloc] init] autorelease];
[self presentModalViewController: nextLevelViewController animated:YES];
What's the best way to have the background make up that gap at the bottom of the image?
Ok, I got it. It was just a question of modifying the view size to be a bit longer, then stretching the image to match it, in the xlb display editor.

How to implement hiding the UITabBar to display an UIToolbar on iOS 11 and iPhone X

I'm trying to do an UI similar to the Photos app, where when you enter in a selection mode that hides the tab bar to display a toolbar.
I have my view controller in a UINavigationController and the navigation controller in a UITabBarController.
I had other strategies before but I'm struggling to get this working on the iPhone X and its bottom safe margins.
If I'm making the correct assumptions based on your description of the Photos App, I think you may be confused as to what the app is doing behind the scenes when going from Photos App TabBar to Photos App Toolbar.
These are two different ViewControllers, the second only shows the toolbar and sets hidesBottomBarWhenPushed = true in the init. You can use the NavigationController's supplied toolbar by setting the setToolbarItems(toolbarItems: [UIBarButtonItem]?, animated: Bool) in your second ViewController. This properly sizes the toolbar in the view to account for the bottom control on the iPhoneX.
If you must manage toolbar and TabBar visibility in the same ViewController, based on my testing, you'll need to add/manage the toolbar manually within a UIView container to get the proper size on all devices. So the view hierarchy would be ViewController.view -> toolbarContainer View -> Toolbar.
for iPhone X, the tab bar height is different than iPhone 8, you need to track
static CGFloat tabBarMaxHeight = 0;
- (void)setToolbarHidden:(BOOL)hidden {
[self.navigationController setToolbarHidden:hidden animated:NO];
CGRect frame = self.tabBarController.tabBar.frame;
tabBarMaxHeight = MAX(tabBarMaxHeight, CGRectGetHeight(frame));
frame.size.height = hidden ? tabBarMaxHeight : 0;
self.tabBarController.tabBar.frame = frame;
self.tabBarController.tabBar.hidden = !hidden;
//! reset tab bar item title to prevent text style compacted
for (UITabBarItem *obj in self.tabBarController.tabBar.items) {
NSString *title = obj.title;
obj.title = #"";
obj.title = title;
}
}

Understanding Creating a UIView programmatically with constraints tutorial?

I'm following this tutorial:
http://matthewmorey.com/creating-uiviews-programmatically-with-auto-layout/
In it (I think) he creates a little red subview and adds constraints to the red subview.
But don't you need to add constraints to the view itself (the green part)?
Lets say you wanted to make the green view always be full screen as the image shows in his tutorial. How would you do that?
The green background will automatically fill an MDMView, whatever its frame is.
This line (already in the tutorial) sets an MDMView to be the view of an MDMViewController:
self.view = [[MDMView alloc] init];
And window.rootViewController automatically fills the window with its view:
MDMViewController *rootViewController = [[MDMViewController alloc] init];
self.window.rootViewController = rootViewController;
So, no, there is nothing more you need to do in code to get the green to fill the screen.
You will, however, need to add a Retina 4 LaunchImage asset to Images.xcassets. It should be 640 x 1136. This serves to indicate that the app should support 4-inch and larger screens. Without this asset, you'll get black bars at the top and bottom on larger screens.
What it is saying is
UIView *contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor greenColor];
self.view = contentView;
It means the green view is main view. You don't need to set constraints for main view. It will always be full screen.

UINavigationController inside UIPopoverController 'Back' animations weird in Landscape

I'm stumped :-\
I have a legacy app in the store that I'm refreshing for iOS 8/9. It was written years ago (pre-ARC) and is a universal app for iPhone and iPad. Everything is now working apart from this ...
On iPad, there is a toolbar at the top of the screen from which I present UIPopoverControllers containing a UINavigationController containing some standard UITableViewController type screens you can drill down into.
In Portrait (and Portrait Upside Down) everything works as expected.
In Landscape however, pressing 'Back' (the standard back not a custom one) causes weird animations - the outgoing controller jumps outside the popover and rapidly slides offscreen (the direction being governed by which orientation the device is in) while the incoming controller simply appears instantly as soon as the outgoing controller jumps outside the popover. I had to use slow animations to determine this as at full speed it just looks like a huge glitch.
There's a short 20 second movie showing the defect here; Note what happens when tapping 'Locations' at 14 seconds in.
If, instead of a UIPopover, I present the VC stack as a form sheet, everything works as expected regardless of orientation. I've also tried the newer UIPopoverPresentationController and experienced the SAME problem, which surprised me a little.
This happens on both of the popovers I'm presenting (one from left of toolbar, one from right of toolbar) and they both have very different internals. The only common factor is that they have a UINavigationController inside a UIPopover.
I've used the view debugger to inspect the view hierarchy, but nothing seems out of the ordinary and I can't capture the view during the glitch no matter how slow I run the simulator so I suspect I'm seeing an internal issue with the popover or navigation controller.
Has anyone seen anything similar? I see this both on-device (iOS 8.4) and in Simulators for iOS 8 and 9.
For context, this project has no storyboards, rarely uses xibs and generally constructs the UI in code within loadView - it really is an old application...
Thanks for any pointers. Not sure how much any code will help here, but here's the presentation of the popover concerned;
LocationsViewController* locationsvc = [[LocationsViewController alloc] init];
UINavigationController *localNavigationController = [[UINavigationController alloc] initWithRootViewController:locationsvc];
localNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[locationsvc release];
UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:localNavigationController];
aPopover.delegate = self;
aPopover.backgroundColor = [UIColor colorWithWhite:0 alpha:0.9];
self.locationPopoverController = aPopover;
[aPopover release];
[localNavigationController release];
[locationPopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I get the same defect with the following, new flavour code;
UINavigationController *destNav = [[UINavigationController alloc] initWithRootViewController:locationsvc];
locationsvc.preferredContentSize = CGSizeMake(320,280);
UIPopoverPresentationController *newPresentationController;
destNav.modalPresentationStyle = UIModalPresentationPopover;
newPresentationController = destNav.popoverPresentationController;
newPresentationController.barButtonItem = sender;
destNav.navigationBarHidden = NO;
[self presentViewController:destNav animated:YES completion:nil];
And the same problem shows when I use UIModalPresentationPageSheet but NOT when I use UIModalPresentationFormSheet.
I had the same issue. The issue was fixed after I added support of landscape orientation to view controllers inside the navigation controller.
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}

How can we place tab bar on top of screen in IOS

I have usually placed tab bar on its as usual bottom I have used following code in application didFinishLaunchingWithOptions for that.
MemberVC *MemberTabBar = [[MemberVC alloc]init];
UINavigationController *navMember = [[UINavigationController alloc] initWithRootViewController:MemberTabBar];
MemberTabBar.tabBarItem.title = #"Member";
MemberTabBar.tabBarItem.image = [[UIImage imageNamed:#"home_icon.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
MemberTabBar.tabBarItem.selectedImage = [[UIImage imageNamed:#"home_icon.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-----------------------
self.tabBarController = [[UITabBarController alloc]init];
self.tabBarController.viewControllers = #[navMember,navEvent,navPromo,navProfile,navAbout];
self.window.rootViewController = tabBarController;
tabBarController.selectedIndex = 0;
I haver found one source to place it in top but i want to find out the better way.
I have gained some knowledge about how to place in top from following git projects. If any one knows some better way then i will be glad to know about that
https://github.com/hollance/MHTabBarController
How to place tab bar on top of screen in iPhone
You cannot move the TabBar to the top. You'll have to create custom one. Check this article about customizing tab bar:
http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/
Basing on it you may move the custom tab bar to the top and acheive desired result
One way is, you can add UIViewController instead of UITabBarController and add a tabBar to that view controller on the top.
This link may help you.

Resources