I have setup AdMob in my ViewController and it's positioned at the bottom. Everything is good until I hide my navigation bar. The AdMob frame goes up when my navigation bar is hidden. How can I make it stick to the bottom of my view? Here's what I have
-(void)navBarTransition:(BOOL)hide
{
[[self navigationController] setNavigationBarHidden:hide animated:YES];
//addjust frame height when ads is visible
if(hide)
{
CGRect frame = CGRectMake(0.0,self.view.frame.size.height + GAD_SIZE_320x50.height,GAD_SIZE_320x50.width, GAD_SIZE_320x50.height);
[bannerView_ setFrame:frame];
}
}
Just before hiding the navigation bar, move the origin.y down by the height of it. Also ensure you have no autosizing masks (flexible top/bottom margins?) interfering with your positioning.
CGRect bFrame = bannerView_.frame;
CGFloat newY = bFrame.origin.y + self.navigationController.navigationBar.frame.size.height;
bFrame.origin.y = newY;
[bannerView_ setFrame:bFrame];
If this doesn't work you could try using CJPAdController (Disclosure: I wrote this class). If you implement this class, you can simply adjust your code to the following (have just tested and it appeared to work as you would like it to):
[[self navigationController] setNavigationBarHidden:hide animated:YES];
if(hide)
[CJPAdController sharedManager] fixAdViewAfterRotation];
I have an app using a UITabBarController, and I have another view that needs to slide up from behind the tab bar controls, but in front of the tab bar's content. If that's not clear, imagine an advertisement sliding up in a tabbed app that appears in front of everything except for the tab bar buttons.
So far I have code that looks something like this, but I'm willing to change it if there's a better way to do this...
tabBarController.viewControllers = [NSArray arrayWithObjects:locationNavController, emergencyNavController, finderNavController, newsNavController, nil];
aboutView = [[AboutView alloc] initWithFrame:CGRectMake(0, window.frame.size.height - tabBarController.tabBar.frame.size.height - 37 ,
320, window.frame.size.height - tabBarController.tabBar.frame.size.height)];
[window addSubview:tabBarController.view]; // adds the tab bar's view property to the window
[window addSubview:aboutView]; // this is the view that slides in
[window makeKeyAndVisible];
Currently aboutView is a subclass of UIView and sits at its starting position at the bottom, but it hides the tabBarController. How can I change this to let the tabs be on top, but still have the aboutView in front of the other content?
You need to add the aboutView as a subview of the view in the currently active view controller in the UITableBarController. You can access that view via the selectedViewController property.
You can add code to your aboutView implementation to animate the view when it appears.
I do something like this in a popup view that I want to appear under the tab bar controls. You can add some code to the didMoveToSuperview message on the aboutView implementation:
- (void)didMoveToSuperview
{
CGRect currentFrame = self.frame;
// animate the frame ... this just moves the view up a 10 pixels. You will want to
// slide the view all the way to the top
CGRect targetFrame = CGRectOffset(currentFrame, 0, -10);
// start the animation block and set the offset
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5]; // animation duration in seconds
[UIView setAnimationDelegate:self];
self.frame = targetFrame;
[UIView commitAnimations];
}
So when your aboutView is added to the selected view controller's view, it automatically animates up.
I have an iPhone application that's using Navigation Controller to display the top bar (with title and back button, and such...).
I added a UITabBar to the application window, that enables to switch between the parts of it. Instead of adding the tab bar to each of ViewController's view I added the bar to app window.
(When I had it in the ViewController, switching between controllers made the tab bar to swipe left/right, when animated pop/push occured, together with whole view).
So, I added the UITabBar to the MainWindow.xib, and tied it to the app delegate's variable. In my didFinishLaunchingWithOptions method, I added the following code:
[self.window addSubview:navigationController.view];
CGRect frame = navigationController.view.frame;
frame.size.height -= tabbar.frame.size.height;
navigationController.view.frame = frame;
tabbar.selectedItem = [tabbar.items objectAtIndex:0];
to resize the main (navigationController's) view, in order to make the TabBar visible.
The problem shows up when I rotate the device -- my view gets stretched to full window and I loose the ability to show the TabBar.
I added a - (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation method to my ViewController, with the following code:
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGRect frame = self.view.frame;
frame.size.height -= [AppState shared].tabBar.frame.size.height;
//frame.origin.y = [AppState shared].tabBar.frame.size.height;
//frame.origin.x = 100;
self.view.frame = frame;
frame = [AppState shared].tabBar.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.origin.y - frame.size.height;
[AppState shared].tabBar.frame = frame;
}
It resizes the view, and moves the tab bar to up/down part of the view (I allow only Portrait/Portrait upside down orientations here). The problem is, my TabBar is turned upside down as well, and also, it's no longer clickable.
It looks like the image below:
Anyone knows how to handle this kind of situation? Or, how to make the tab bar not tied to view controller, but also able to handle interface's rotation smoothly?
You are using the tabbar in an unintended way. You seem to be using the UITabBarView as an uncontrolled element of other views. That is not it's function.
The UITabBarView should be controlled directly by a UITabBarController which in turn should be controlling all the view controllers for the views displayed in the tabbar i.e. the tabbar controller is a type of navigation controller that controls subcontrollers.
Suppose you have three tabs and the third one is a navigation controller. Your controller hierarchy would look like this:
TabbarController:
-->tab1ViewController
-->tab2ViewController
-->tab3ViewController(UINavigationController):
-->rootViewController-->secondViewController
You are trying to move and manage the tabbar view without its controller and the proper controller hierarchy. That isn't going to work.
At some part of my code I am using this line
[[self navigationController] pushViewController:myController animated:YES];
This works perfectly and pushes a view, coming from bottom, over the current one, covering the last one completely.
I am wondering if there's a way to make it cover just part of screen. Let's say, just the half bottom of the screen...
Is it possible? I have tried to change the controller's view frame but the size kept coming full screen.
thanks.
Instead of using a new view controller modally, you could add a new subview to your existing view, using the same view controller.
You can do the "slide in" animation with something like:
[self.view addSubview: newView];
CGRect endFrame = newView.frame; // destination for "slide in" animation
CGRect startFrame = endFrame; // offscreen source
// new view starts off bottom of screen
startFrame.origin.y += self.view.frame.size.height;
self.newImageView.frame = startFrame;
// start the slide up animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.3];
newView.frame = endFrame; // slide in
[UIView commitAnimations];
You can do it in a limited fashion with a modal view controller. Check out the presentation options available under UIModalPresentationStyle in the apple docs.
You will need to be on iOS 3.2 or above to do a modal view controller.
I have been unable to google an acceptable solution to this that can be applied to my project.
My app is a graphing tool that has three tabs; one for the graph itself and the other two are for browse/search functions for things that can be added to the graph. All tabs are navigation controllers.
The tab for the graph itself, when in portrait mode, displays a small preview of the graph and lists details of each entity that is on the graph below, and displays the tab bar at the bottom.
When the user rotates into landscape mode the graph turns full screen and everything else, including the tab bar, disappears. This is where I'm having the problem, as the GLView for my graph is always obscured by a white rectangle where the tab bar was.
I have tried changing the size of the navigation controllers view to full screen, changing the size of the tab bar controllers' view to full screen, changing the frame size of the tab bar itself to CGRect(0,0,0,0), becoming emotionally distraught, banging my fists on the desk, shouting abusive language at the MacBook, etc; all to no avail.
How can I make it work?
I had this problem, and I've resolved it by changing tabbar's subview frame for my content view (there are 2 subviews in tab bar - content view (#0) and bar view (#1)):
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:FULLSCREEN_FRAME];
I had the same problem and found the answer here : UIView doesn't resize to full screen when hiding the nav bar & tab bar
just resize the tabbarcontroller view this when you hide the tabbar :
tabBarController.view.frame = CGRectMake(0, 0, 320, 480);
It seems to have the problem with hiding the Bottom bar as Tab bar.... which I was facing and googled a lot for this.I consider it as a bug with this tab bar.Then also....we can use some trick.....
You can try for this and will definitely help if you are trying to hide the tab bar and which leaves the white space..
for the hell of coding you need to write just
[self setHidesBottomBarWhenPushed:YES];
when you are pushing to other view,where you don't need the Tab bar just write it
twitDetObj=[[TwitDetail alloc] initWithNibName:#"TwitDetail" bundle:nil];
[self.navigationController pushViewController:twitDetObj animated:YES];
self.hidesBottomBarWhenPushed=YES;
[twitDetObj release];
Hope this will work for you.....
This one works for me:
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];
I had this code within the tab's viewControllers.
NOTE - This solution is to just to remove white space left after hiding tab bar.
For hiding tab bar best solution is - #Michael Campsall answer here
The simplest solution to this is to change your view's(in my case its tableView) bottom constraints, instead of giving bottom constraints with BottomLayoutGuide give it with superview. Screenshots attached for reference.
Constraints shown in below screenshots creates the problem, change it according to next screenshot
.
Actual constraints to remove white space should be according to this(below) screenshot.
For those who is still struggling with this. I have found that the problem lays on the constraints. Tab Bar is hidden, yet it already changed my constraint from Storyboard.
SWIFT 3+
self.tabBarController?.tabBar.isHidden = true
let cons = NSLayoutConstraint(item: textview, attribute: NSLayoutAttribute.bottom,
relatedBy: NSLayoutRelation.equal, toItem: self.view,
attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 0)
view.addConstraints([cons])
In my case "textview" was the item, which supposed to fill the white space from hidden TabBar.
Are you sure it's obscured and not just A) not redrawn or B) the frame of your GLView doesn't occupy that space?
some of the superviews of currentViewController.view of the tab bar view controller has clipToBounds set to YES (it's class name is UITransitionView, if not mistaken). To access it use
tabBarController.currentViewController.view.superview.superview.clipToBounds = NO;
after doing this your attempts of resizing a view will not be limited by anything and will succeed. Good luck!
This is just a workaround, but have you tried presenting the graph modally when the user rotates to landscape? This should obscure the tab bar.
You can avoid the transition with
[viewController presentModalViewController:graph animated:NO]
its because the space where tab bar was , not allocated to other views when u set tab bar hidden u can set the corresponding view to stretch or fill the whole screen like scale fill or aspect fill something like that or take a view bigger than the iphine screen so that when u change the phone to landscape it can complete fill the screen
Check the UIView underneath. It may be set to white, so when you hide the tab you're revealing the white UIView. Try setting the UIView to Transparent.
I think u need to set self.navigationController.view.frame to full size ie to UIApplication screen frame before u set tabbar hidden
On after unhiding tababr and reaching to particular view. Tabbar was showing white space on above uitababr. This solved my problem
-(void)viewWillAppear:(BOOL)animated
{
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 568)];
}
in the view pushed
- (BOOL)hidesBottomBarWhenPushed
{
return YES;
}
- (void)hidesTabBar:(BOOL)hidden {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0];
for (UIView *view in self.tabBarController.view.subviews) {
if ([view isKindOfClass:[UITabBar class]]) {
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
}
} else {
if([view isKindOfClass:NSClassFromString(#"UITransitionView")]) {
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
}
}
}
}
[UIView commitAnimations];
}
My solution: set self.edgesForExtendedLayout = .None in your view controller's viewDidLoad().
I'm assuming that you've already checked the autoresizing arrows on your view?
Have you tried hiding the UITabBar with
tab_bar.hidden = YES