iPad autoresizingMask creating bottom margin - ipad

LiveStreamTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 768, 960)];
LiveStreamTable.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:LiveStreamTable];
This code is in viewDidLoad. In between viewDidLoad and viewWillAppear the table is resized to 916 height leaving 44 empty px at the bottom (this is in portrait mode). I know it's in between from printing debug info.
The view has a status bar and a nav bar at the top, so 960 should fill up the whole screen just right. And it does with the autoresizingMask line commented out. I only want autoresizingMask to affect it when the iPad is rotated so that landscape mode works.
I'm also having a problem where if I go to the screen in landscape in the first place then it gets sized wrong. It ends up a little too wide and too short. I assume that's related.
How do I use autoresizingMask correctly so that my table will take up the whole view (except status and nav bars) in both portrait and landscape?

Your autoresizing mask is correct, but the way you init the frame is not.
Consider if this view is opened in landscape, frame (0, 0, 768, 960) yield the wrong frame.
instead of
LiveStreamTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 768, 960)];
you should try
LiveStreamTable=[[UITableView alloc]initWithFrame:self.view.bounds];
This will initialize the frame according to your current ViewController's view.
I hope this help.

Related

iAd frame doesn't rotate to landscape using setAutoresizingMask on iOS8

I have created an iAd frame right on top of the tab bar and I am using setAutoresizingMask to keep it in the right place when rotating the screen. Here is my code in viewDidLoad:
iAd = [[ADBannerView alloc] init];
bannerIsVisible=NO;
iAd.delegate=self;
[iAd setAutoresizingMask: UIViewAutoresizingFlexibleTopMargin
| UIViewAutoresizingFlexibleWidth];
// set iAd frame
iAd.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 50);
[self.view addSubview:iAd];
This will create the banner just below the screen, so it will appear when the ad is loaded using the bannerViewDidLoadAd: delegate method and going back using the didFailToReceiveAdWithError method.
This works perfectly on iOS 6 and iOS7.
On iOS8 the banner appears in the right place when portrait, but when I rotate the screen to landscape, the banner appears around 10 points over the right place. Is like it doesn't take into consideration that the height of the frame is smaller when landscape.
Did something change in iOS8 about setAutoresizingMask?
Thanks

Programmatically setting content to fill screen between tab bar and nav controller

I have a UIwebview that I want to fill the screen between the navigation bar at the top and the tab bar at the bottom. My web view is being defined programmatically and I was initializing it with a frame as below.
I have been able to get the desired behavior by hard coding in some values, but I have seen that this does not work across all devices. Specifically, it seems that different OS's might consider (0,0) as different points on the screen (the top left corner of the screen for some, and the top left most corner under the nav bar for others).
My question is, how do I set the web view position and size to fill the screen across all devices? And can anyone explain why this doesn't behave as I think it ought to?
//iphone 5s running iOS 8
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight+20)];
//iphone 5 running iOS 7
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, screenWidth, screenHeight-93)];
//what i thought would work for all, but doesnt fill the height of the screen...
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];

iOS - UIPageControl cuts bottom off

I'm creating a UIViewControl with this this website. I finished it, but when I load my image, the bottom of my image gets cut off. I'm sure the dimensions of the image are correct, besides the UIImageView is stretched throughout whole screen.
Since the whole code is on the site, I won't be adding anything here, except for one line I changed.
I changed
self.pageViewController.view.frame =
CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height - 30);
to
self.pageViewController.view.frame =
CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height);
The gap got smaller but is still there. It looks like this
Thank you.
Have you taken into account the height of the status bar at the top of the phone?
I think that in iOS 7 the status bar overlaps the content by default, you might have to slide the content down a bit.

Screen bounds extends visible area

I'm trying to make a square (50 x 50) UIView in the lower right hand of my main view, but I'm confused about why it's not entirely visible. In this instance, only the tip of it is visible from the bottom. Am I confusing some concept?
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIView *transparentFloater = [[UIView alloc] initWithFrame:CGRectMake(width - 50.f, height - 50.0f, 50.0f, 50.0f)];
[self.view addSubview:transparentFloater];
Try to add the autoresizing mask:
transparentFloater.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
If I am not wrong, You have created your ViewController with xib and in the attributes of view, you have forgot to mention that you are using a "navigation bar" as "top bar".
Reason
So in ViewDidLoad, view in .xib with a height X is returned. But as you might have loaded the viewController using UINavigationController, after loading the height of view is decreased by 44pixels.
Suggestions :
1) Whenever you know that you are going to have navigation bar on top please mention it in .xib file as well.
For doing so click on the view in xib and select the option called topbar in attributes Inspector of utilities area
2) Call the following api
NSLog(#"In ViewDidAppear %#",NSStringFromCGRect(self.view.bounds));
in
viewDidLoad
viewDidAppear
to track whats happening with the bounds of view
You does not need to do anything just put
transparentFloater.backgroundColor = [UIColor redColor];
because your view (custom) is invisible (because your main view color and custom view color are same (white) ) may be. I tried your code in my demo project. it worked perfectly for me.

How come a UIViewController's view coordinate system starts after the navbar, but its height includes the navbar?

I noticed that with a NavigationController on an iPhone, the height is 460. So it includes the whole screen except the status bar.
However, when I add something at coordinate 0, it shows up after the NavigationBar, although the size of the navigation bar is included in the height (meaning the entire frame of this view sticks off the screen).
Did I make a mistake? If not, why is it structured this way?
NSLog(#"Frame: %#", [NSValue valueWithCGRect: self.view.frame]); // prints {(0, 20), (320, 460)}
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame: CGRectMake(0, self.navigationController.navigationBar.frame.size.height, self.view.frame.width, 50)];
[self.view addSubview: scrollView]; // showing up 44px *after* the nav bar
I already answered your other similar question, but here is one for this.
In viewDidLoad you will see the views height as 460 because at that point it hasn't resized to account for the Nav Bar.
But If you printed the same frame out in say viewWillAppear you will see that now the frames height has adjusted for the Nav Bar.
So if you want to add something in viewDidLoad, you need to add it based on the views frame, add whichever resizing mask will do the job you want, and see it adjust correctly once the view appears.

Resources