Navigation bar in UINavigationController too short - iphone

I'm putting together an app where some of the views are in regular UIViewControllers and use their own UINavigationBar, whereas others will be part of a navigation hierarchy inside a UINavigationController and make use of its UINavigationBar instead.
The problem is that the actual UINavigationBars that I'm seeing are different in these two cases. The ones in that use a UINavigationController's navigation bar seem unnaturally short. Here are some pictures, showing what I see in Interface Builder versus what I see at runtime.
I can't figure out what I'm doing wrong here. Why are the navigation bars different heights? How can I make them the same?

I truly believe you are mixing up two different features. UINaviationbar and UIToolbar. Here is apple's human guidelines. Look at the top of the document for Navigation Bar
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW41
I will try to see if I can find a document on their dimensions. Here is one. I am sure there are better ones available
http://www.idev101.com/code/User_Interface/sizes.html

Figured out what was going on here. UINavigationController resizes the navigation bar in portrait orientation automatically, and as far as I can tell, there is no built-in way to prevent this from happening. However, with the help of this post (How to prevent autoresizing UINavigationBar on Landscape), I was able to get it working the way I wanted. My code was slightly different from the code in the linked post. I used:
#implementation UINavigationBar (CustomHeight)
- (CGSize)sizeThatFits:(CGSize)size
{
// Need to know the width of the window
CGRect bounds = self.window.bounds;
// Sometimes height and width are turned around. Take the largest of height and width as the real width.
int width = (bounds.size.width > bounds.size.height) ? bounds.size.width : bounds.size.height;
// Make sure that the
CGSize newSize = CGSizeMake(width, 44);
return newSize;
}
I'm not sure if there's a better way to get the true width - the above is clunky but works for me since my app only runs in landscape. My bigger concern is that Apple says in its UINavigationBar documentation that you shouldn't directly adjust the frame. But I guess I'm not directly doing that; presumably internal drawing methods will call this method and do their thing.
Anyway, this works for me. Hope it helps someone else.

Related

iOS: Is is possible to make a UINavigationBar taller and "push" the other views down the screen?

Is there a way to make the "content" area of an iPhone app aware of a larger navigation bar?
Similar to these questions:
iOS: Adding a fixed image just below the navigation bar
iOS: Positioning navigation bar buttons within custom navigation bar
I've managed to use the 1st questions sample code to add a category on UINavigationBar and change its height, and added a subview where I need it, but I can't see a way to cause the UITableView (or indeed any content views) to take its height into consideration:
(The colors are only to make the different views distinguishable)
The accepted answer to the first question sets the nav bar's frame in -layoutSubviews, which is anywhere from "ewwwww" to outright wrong depending on the assumptions made by other layout code.
Instead, override -sizeThatFits: to return a more appropriate size.
I'd go about this by adjusting the tableView.frame, so something like this:
CGRect navFrame = self.navigationController.navigationBar.frame;
CGRect tableFrame = self.tableView.frame;
tableFrame.size.height = tableFrame.size.height - navFrame.size.height;
tableFrame.origin.y = navFrame.size.height; //move it down by the height covered by the navigation Bar
self.tableView.frame = tableFrame;
You could do this with your other views as well - i.e. by simply adjusting the frame.
I've not got XCode on this computer, so I've not checked the code - just written it out as an example, so please check it yourself before using it!

iPhone - What is the control in the middle of the in call screen?

As a small project to get myself used to some more iPhone elements I've decided to create a sample in call screen, modeling it on the native iPhone call screen (IOS 4)
However I'm struggling to make out what elements the native in call screen uses to make up the view that is displayed.
I was wondering if someone with more experience on iPhone could help me out by explaining what the various elements are?
Is the bottom part a UIActionSheet that is slightly transparent and with a UIBUtton placed over it? Or is it a slightly transparent imageview with the button over-layed?
Similarly at the top, it looks like its an imageiew with the name or number of the callee/caller and the call duration underneath, would I be correct in thinking that?
The part I'm really interested in is the bit where the icons are held in some sort of dialog in the centre of the screen that is animated to swing around to a keypad when it is selected, is this some sort of iPhone control that I can use or customise?
EDIT:
I've tried two things to try to achieve this so far:
1) I've created a view within a view and I am trying to flip this however I can only seem to get the main view to flip properly and not the view inside it which is the one I want and it doesn't seem to be a good approach.
2) I've tried to look at using the Utility application approach to it but again this seems to be for flipping the full screen and not just a section within a screen (view)
Has anybody got any pointers on what to try next? Or if one of the above methods is the ideal way to do it and should be investigated further?
At a basic level, I would say that the panel of 6 buttons is simply a view with 6 buttons laid out in it as subviews.
The rounded corners and border stroke can be achieved by accessing the view's layer property and the layer's properties for cornerRadius, borderWidth, and borderColor, e.g.
view.layer.cornerRadius = 10;
view.layer.borderWidth = 2;
view.layer.borderColor = [UIColor whiteColor].CGColor;
This requires including the CoreGraphics Framework, and the appropriate header files in your code.
I notice there's a gradient (or it appears to be a gradient) in the border stroke. I am not sure how to achieve that without doing something more involved and clever (such as a containing view that is just slightly larger veritically and horizontally than the view containing the buttons and is filled with a gradient color. The result would be a gradient border, but this doesn't seem like the best way to do that...
The flip is actually pretty easy. You can create a UIView animation with something like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:view cache:NO]
[UIView commitAnimations];
Does this help, or at least get you started?

Strange black bars in UITableView

I'm really scratching my head over this one: When I make visible the Toolbar of the navcontroller in my view hierarchy, strange black bars appear at the top and bottom of the table view. http://grab.by/8pgz
The app is universal, and on the iPhone simulator (or device) this does not show up, although they use the same UITableViewController subclass.
I cannot even figure out what the extra bars are, which makes it even harder to come up with a solution.
They are, however, not navbar / toolbar. They are not section or table view header / footer. It does not merely seem to be a resizing of the table view either, since its background is not black.
The custom table view controller sits inside a UINavigationController, which in turn is inside a UISplitViewController. Pretty standard, as far as I understand.
Like said, they do not show up on the phone - nor do they appear in the popover in portrait orientation.
I'm really out of clues here. Any suggestions would be most welcome.
Cheers,
Gregor
Sweden
Update: Problem solved by moving the code for making toolbar visible to -(void)awakeFromNib method instead of -(void)viewDidLoad. Still don't know what went wrong, but now at least it works.
I believe there is a problem with the frame you're trying to use to initialize the tableView.
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, height, width);
Try changing the height width variables in code, to reflect your height & width on the iPad.

How to draw in UIViewController in landscape orientation on the iPhone?

there are already some questions on this topic. Unfortunately none of them helped me in anyway. So here is the thing. I am working on an app atm and it has one tabcontroller with two tabs, which contain multiple navigationcontroller on top of each other. Now in one tab at the top level navigation controller, I want to draw some graphics in landscape orientation.
Unfortunately using the shouldAutorotateToInterfaceOrientation method returning YES does not help in anyway.
Now I was wondering whether I could just hide the statusBar and the navigationBar and then draw my graphics so that it looks like it is landscape orientation. But then I also would like to add some labels. I am quite sure I also could turn those around 90 degrees. But this is probably not the right approach here. And I want to submit my app someday...
So now I was hoping someone knows whats the best approach here and how to realize it.
Thanks.
I found a solution somewhere else. The idea is to use the CGAffineTransform method. It allows you to transform the complete coordinate system of a uiview. The piece of code underneath rotatets it to landscape. Now when you draw, the drawing relates to the rotated coordinate systems and everything is drawn in landscape orientation.
CGAffineTransform transform=CGAffineTransformIdentity;
transform=CGAffineTransformRotate(transform, (90.0f*22.0f)/(180.0f*7.0f));
transform=CGAffineTransformTranslate(transform, 80, 80);
This does what I want. But anyway, if there are any other suggestions, please post them!

UIView Clipped By Statusbar until Autorotate

Ive created a multiview application that uses multiple controllers to display and control views. The problem Im having is, when the simulator initially loads the view the header is partially covered by the bar at top of screen and the tool bar at the base is not touching the base of the screen. I used the Interface builder size attributes to control the view when the iphone rotates and it works perfectly. All smaps into place perfectly both in landscape and portrait mode AFTER a rotation but the problem is with the initial load before a rotation occurs.
Your thoughts a much appreciated.
Tony
I grappled with this issue for days and days--no amount of fiddling in IB worked.
Ultimately I got it to work by adding this line:
mainViewController.view.frame = window.screen.applicationFrame;
to the application:didFinishLaunchingWithOptions: method. (Where mainViewController is the primary UIViewController).
I've had issues with views being clipped by status, nav, and tab bars. I've fixed most of them by using the Simulated Metrics feature in Interface Builder. That way what your laying out in IB is a lot more accurate to what your actually going to get.
I ran into this issue too. Specifically, when displaying an ADBannerView, my whole view would shift and be under the status bar and leave a little empty space just the size of the status bar at the bottom of the iPhone screen. Here's how I solved it : (Adam's answer here helped me figure this out):
// In the function that displays an iAD Banner
CGRect contentFrame = self.view.bounds;
CGRect myStatusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGFloat statusHeight = myStatusBarFrame.size.height;
// Set the view's origin to be under the status bar.
contentFrame.origin.y = statusHeight;
I needed to set the origin of my view to be below the Status bar, and that solved the issue for me.
The problem is that you're adding your controller "incorrectly" according to Apple docs (although IMHO Apple designed it badly - the default should be that you don't need to shift!)
if you're going to have a status bar, Apple requires that you "manually" shift all your controllers down by 20 pixels (more accurately, by the height of the statusbar - although that's always 20 pixels today, Apple lets you request the height at runtime, from the "statusBarFrame" property in UIApplication)
Apple's classes - e.g. UINavigationController / UITabBarController - automatically shift themselves down by 20 pixels when they're added to the screen. Both classes have a bug where they will do this shift even if they are not the main controller - so your app suddenly shifts down an extra 20 pixels, leaving 20 pixels of white space at top.
But, when they rotate, those classes often "get it right" and move back into place. Or vice versa.
c.f. this link for a much more detailed explanation of what's going on, and how to write your code the way Apple wants you to:
http://blog.red-glasses.com/index.php/tutorials/iphone-auto-rotation-for-intermediate-developers-tutorial-1/