UIView Clipped By Statusbar until Autorotate - iphone

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/

Related

iphone 5 and storyboard setting autoresizing masks

I've got a storyboard-driven application, and I'm trying to modify it to support the iPhone 5.
There is a navigation controller, and then my menuViewController. In viewDidLoad of the menu controller, I have verified that self.view.frame is {{0, 0}, {320, 568}}. The view controller's size is set to "Inferred" in the Simulated Metrics, and the main view has "Autoresize Subviews" checked.
But my subviews are not getting resized! (Note that I can manually resize them in code, that's not a problem, but I would really like this to "work" using mostly IB, since I have a lot of views, and that would be about a million times easier.)
I have a full-screen subview that doesn't get resized. It's mask has basically everything enabled.
I also have subviews that are supposed to float at either the bottom or the top, and the ones that float at the top work, but the ones that are supposed to float at the bottom don't.
What should I be checking here? It's probably something stupid that i'm missing, but I've been scratching my head for an hour, and am getting close to just changing all my frames in code. (Which would be ugly as well as inelegant.)
Thanks!
I found a hint here: How to resize App for Iphone 5?
Essentially one of the answers there suggests editing the xml of the storyboard directly. I went in and looked, and the top level view in my viewController had autoresizesSubviews="NO" I changed it to YES, and that fixed the problem for me.
As stated in my original post, I absolutely know for sure that checkbox was checked in the inspector pane. I have no idea why the xml didn't match the inspector.
Check the springs in the autoresize control for your view (not the view controller) within the metrics pane. Try and make them like in the picture below.
Notice that you will not be able to set the internal springs for a top-level view object (but that's fine: just ensure the 4 side ticks are all activated).
Hope this helps.

Why do my UIImageviews get resized/dimmed when using UINavigation/UITabbar controller

I have an app with a primary view that has a UITabBarController with 5 tabs. Each tab is a UINavigationController.
In interface builder, I'm customizing the background of each page by dragging a UIImageView and setting it fullscreen. The image I'm setting to the view is 640x960. I am setting it to be Aspect Fill.
However, what I've noticed is that it is not where I would expect it to be. When navigating between by tabs, the image seems to be shifted down from where it should be.
Also, when pushing a new view to the navigation controller, the background of this new view isn't offset in the same way as the tabbar one, and it is also slightly dimmed.
How can I set my UIImageViews on each page to be aspect correct and fill the screen 1:1? Also, how does one disable the dimming when pushing a view to the navigation controller?
Thanks for any tips, and apologies if this is covered in another thread, I couldn't find an answer searching the site.
Assuming that you are using the IB to setup your views, you should select navbar/tabbar options to reflect what will be on the actual page. That should place your image correctly. I would also recommend that you make both a low res and hi res version of your background images -- 320x480 and 640x960. Of course, your size may need to be adjusted (reduced) for the navbar and/or tabbar which will leave less than 960 px of vertical height -- probably more like 920px if you are in portrait mode. Then you add #2x to the base name of the hi res version, this would account for older iPhone screens.
Once you have the image placed correctly, resizing should be unnecessary. You can have the image automatically resize width and height using the little arrows on the layout page -- that's a bit hard to describe. It can also be done in code -- if you still need that I can provide a sample.
Maybe you need to set all AutoresizingMask in order to resize the UIImageView properly on each view. And to main aspect ratio u should use either AspectFill or AspectFit on the contentMode.

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.

Views and buttons unresponsive to touches after rotation

I am coding against iOS 3.0 and I am trying to add rotation (landscape) support to my app.
Everything about the rotation was easy enough. However, after rotation to landscape mode from portrait, the right-third of the screen (480-320) is unresponsive to all events (touches, drag, etc.). I've verified that the key window is receiving the events but those events are not being passed to the buttons and UIViews on the right (in landscape) side of the screen.
I am using NSNotificationCenter to receive orientation changed events (and not using autorotate flag).
I did see: link text but that wasn't very helpful to my case.
Stuck. Need help. Thanks.
I've fixed the problem I was having .. I basically needed to do [self.navigationController.view setNeedsLayout].
The way I understand this (which maybe incorrect is that self.navigationController.view.frame was same as self.view.frame and both were equal to (x=0,y=0,width=320,height=480). I then rotated self.view by M_PI/2 and did a number of frame manipulation on select self.view.subviews to get everything to animate/position/scale correctly.
That worked out okay but the navigation controller was not willing to acknowledge touch events to parts of self.view there were to the right of 320. In essence, if this self.navigationController.view.clipsToBounds were true, it might not even have shown that part of self.view.
Anyway, setting setNeedsLayout on the navigation controller's view resolved the issue. I hope this helps someone else.

iPhone force rotation

I have been reading a ton on rotation, but not finding a solution to my query. Here goes:
I have a portrait application with a tabbar and hidden navigation controller in my tab. At a point in the app, the next view must be landscape.
The XIB layout has been done in landscape, so I want to bring up the xib without any translation or pixel moving code. (not thinking this is required) I have tried just pushing the view (remains in portrait), shifting the view using various methods (non seem to line thing up properly).
Is there a way to tell the view that it is already laid out for landscape prior to it being opened?
Thanks in advance!
Found it, this code does the trick in the viewdidload:
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
Still have 1 odd thing. No matter what I do to set the navigation bar to hidden, it does not rotate, and stays at the left side of the view.
[[self navigationController] setNavigationBarHidden:YES animated:NO];
Has anyone seed this behavior and solved?
I'm positive that you cannot 'force' a rotation. The system decides when to change the orientation of the device; so the 'orientation' properties are essentially read-only. I looked into this same problem a long time ago when I wanted to make sure a particular view always displayed in one orientation.
Due to this, most apps allow all of their views and view controllers to work in any of the orientations the app supports. I've found that trying to restrict the behavior of some views and view controllers ultimately creates more hassle, and can cause issues when transitioning between views and view controllers.
The code you posted will work for your view. You are not actually changing the orientation at all; your view is just behaving like it has been rotated by drawing in a rotated fashion. I'm not sure if you can do the same thing to the navigation bar or not, but it's worth a shot. If you are able to control the view properties of the navigation bar (it is a UIView as well), applying the same pattern you are using for your custom view should work.
Most apps that want a view to only be in landscape ultimately force their entire app to be in landscape. For instance, Flight Control only supports one orientation. Thus, the drawing code is pretty simple; regardless of orientation, just draw the view and rotate it to the one orientation it supports (either landscape left or right).
Your app's design wouldn't be that easy... it sounds like you are not designing a full-screen app. You would have to worry about the navigation bar and status bar being properly drawn.