I'm using a UITabBarController with UINavigationControllers like this
I add this to the view using
tabctrl.view.frame = CGRectMake(0, 0, 320, 548);
[self.view addSubview:tabctrl.view];
The screen looks like
But I can't switch to other tab(ie, touching on tabctrl's tab has no response)
If I change the frame like
tabctrl.view.frame = CGRectMake(0, 0, 320, 488);
then the screen looks like,
Now, I can touch the tab and switch to required viewcontroller. How to solve this issue?
I need to get access to the tabctrl when its frame height is 568.
I'm using xcode 4.6.2 and ios simulator 4inch retina.
Use this code:
[appDelegate.window setRootViewController:tabctrl];
rather than:
tabctrl.view.frame = CGRectMake(0, 0, 320, 568);
[self.view addSubview:tabctrl.view];
Your tabbar controller might be behind something else on the bottom of the screen. You can test it with code:
[self.view bringSubviewToFront: tabctrl]
If this fixes your problem, try to find which view is in front of your tabbar controller
Set your rootViewController's wantsFullScreenLayout property to YES
tabbarController.wantsFullScreenLayout = YES
This should solve your tabbar switching issue on 4-inch screen
Related
I am creating a UINavigationBar programmatically, which is displaying as intended in iOS 7. However, in iOS 8.x all the text in the UINavigationBar doesn't appear within the bounds of the screen. One of my assumptions is this has something to do with Auto Layout.
//ViewControllerRootHomeCenter.m
_navBar = [[UINavigationBar alloc] init];
_navBar.frame = CGRectMake(0,0, self.view.frame.size.width, 64);
// add hambuger menu
//...etc etc
[self.view addSubView:_navbar];
You can try to obtain the screen width this way too:
CGRect frame = (CGRect){0,0,CGRectGetWidth([[UIScreen mainScreen]bounds]),64);
Perhaps it will fix your problem.
First of all, make sure you're not hard-coding the width of the navigation bar.
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
Secondly, if your auto layout is enabled, make sure there are no conflicting constraints. If it's not enabled, then I don't see why you should be having this problem.
I'm solving the status bar issue in iOS 7 using
if(st.version == 7)
{
CGRect screen = [[UIScreen mainScreen] bounds];
CGRect frame = self.navigationController.view.frame;
frame.origin.y = 20;
frame.size.height = screen.size.height - 20;
self.navigationController.view.frame = frame;
}
Since I'm using navigation controller and pushing from one to another using [self.navigationController pushViewController:newone animated:YES];. It works fine in all view controllers. But, if the viewcontroller has mkmapview in xib, status bar issue of ios 7 occurs.
If I delete the mapview form xib and push to that view controller means, it will be like,
If I add the mapview even by code below,
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
[self.view addSubview:self.mapView];
It looks like,
How to solve this?
if(st.version == 7){
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 120, 320, 100)];
}else{
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 100, 320, 100)];
}
If you add mapView in viewWillAppear replace it in viewDidAppear.
Maybe you have this issue because you're doing manipulations with view's frames before your view is completely set up
I would highly suggest against doing it like that.
If you're using interface builder, then add constraints based on how you want your application to look and the frame will auto adjust itself.
If you're not using interface builder, then still use constraints, but get a good tutorial about making constraints programatically (as I don't know how to do it myself).
Edit: The reason I HIGHLY suggest not doing it with hardcoded numbers is that it'll be a pain to do iOS 6/7 Landscape/Portrait 3.5/4 inch screens. That's 8 cases.
i think you have some adjust your navigation Y position set -20px. that way it goes overlay. use this code your ViewController
CGRect screen = [[UIScreen mainScreen] bounds];
CGRect frame = self.navigationController.view.frame;
frame.origin.y =0;
frame.size.height = screen.size.height;
self.navigationController.view.frame = frame;
or may it you have use wantFullScreenLayout some where in your project
setWantsFullScreenLayout = YES:
statusbar section is located to the (0,0) point to catch.
Statusbar and as large as the size of the current view to increase the value of mainScreen change the size of the bounds.
Statusbar change the style of the translucent style.
this below link you get some clear idea about your issue
How do I get the navigation bar in a UINavigationController to update its position when the status bar is hidden?
Override the -edgesForExtendedLayout method in your view controller
-(UIRectEdge)edgesForExtendedLayout {
return UIRectEdgeNone;
}
If you want to hide status bar from a particular view add this method in that particular view.m file
- (BOOL)prefersStatusBarHidden
{
return YES;
}
What about setting self.automaticallyAdjustsScrollViewInsets = NO; in viewDidLoad of your view controller or in IB?
Try to set MapView(ScrollView) automaticallyAdjustsScrollViewInsets = NO;
Try to set edgesForExtendedLayout to UIRectEdgeNone;
Try to use UIViewController.topLayoutGuide, see the Q&A from apple about this issue:Preventing the Status Bar from Covering Your Views.
Try to use the bar position delegation, see UIBarPositioningDelegate Protocol Reference
According to your description and screenshots, you are trying to move the whole UINavigationController.view.frame 20 pt, and the MapView(ScrollView) did something to prevent it happened (or re-set), put some breakpoint and log to track the frame of UINavigationController.view.frame changed.
Could you please provide a sample project? I'm so curious about what really happened.
try this
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.translucent = NO;
}
- (void)viewDidAppear:(BOOL)animated
{
self.navigationController.navigationBar.translucent = YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[application setStatusBarHidden:YES];
return YES;}
Please add this line to your code.This will hide the status bar from your app.
If you have a xib. Did you try to enabled Top Bar in simulated Metrics ?
I'm having a similar problem as asked here: UIToolbar at the bottom not working in Retina 4 simulator.
My UIToolbar is not responding to touch on my iPhone 4. The toolbar is visible and at the bottom of the screen. Only when I move it up it will respond to touches.
so far no solution has worked for me.I'm using a storyboard and I have tried
enabling use full screen on all viewcontrollers and putting self.view.frame = [UIScreen mainScreen].bounds;in all my viewdidload methods.
I've also tried placing [window setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; in my appdelegate.
found the problem. I was initialising one of my VC's with the wrong frame size.
I have graphical issues using the UISearchBar.How can I fix it ?
here's my code:
[self.view addSubview:self.resultObject.searchBar];
I have add
self.searchBar.frame = CGRectMake(0, 0, 320, 1);
[self.searchBar sizeToFit];
to viewDidLoad but I still have the same problem.
Thank you a lot
You should place your search bar at (0, viewController.topLayoutGuide.length); you are adding it at (0,0). In iOS7, views are by default under the status bar.
This is an already posted question but I need to understand what is going on with the following scenario. I'm developing an iPad application and I created a UINavigationController like the following (test purposes).
UINavigationController* navigationController = [[UINavigationController alloc] init];
navigationController.view.backgroundColor = [UIColor redColor];
Once created, I added the UINavigationController's view as a subview of a UIViewController.
[self.view addSubview:navigationController.view];
The result is displayed in the following image:
As you can see, there is a gap between the status bar and the navigation bar of the UINavigationController. Since the view of the UINavigationController is red, it seems that the frame of the navigation bar has that gap.
I've found an hack to fix the problem. By setting the frame for the UINavigationController, the navigation bar goes in the right position.
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect frameRect = CGRectMake(navigationController.view.frame.origin.x, navigationController.view.frame.origin.y - statusBarFrame.size.height, navigationController.view.frame.size.width, navigationController.view.frame.size.height);
navigationController.view.frame = frameRect;
Now, since I don't like very much that hack and I would understand what is going on, do you have any suggestions to find an elegant solution to resolve the problem?
Thank you in advance.
That 20px offset is for status bar, navigation controller is designed to be full-screen, but you are adding it to the subview of the main view.
viewController setWantsFullScreenLayout:YES
It may help you.
This is the fix that really solved all the problem. So thought of posting it as it might really.
How this works
This gonna set my navigation bar origin to 0, and in turn the view of navigation is also set to 0 which takes the reference of Navigation Bar, which solves all the mess :)
And 44 is the heigh of Navigation Bar in the code. :)
Put the code in ViewDidAppear,
CGRect windowFrame = [UIScreen mainScreen].applicationFrame;
//Setting the Origin to 0 of both Navigation Bar and Navigation View for Both Landscape and Portrait
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, windowFrame.size.width, 44)];
[self.navigationController.view setFrame:CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height)];
}
else{
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, windowFrame.size.height, 44)];
[self.navigationController.view setFrame:CGRectMake(0, 0, windowFrame.size.height, windowFrame.size.width)];
}
[self setWantsFullScreenLayout:<#(BOOL)#>];
is deprecated. If you want to add subviews to your ViewController without worrying about NevigationBar use:
self.edgesForExtendedLayout = UIRectEdgeNone;