I've created a UIScrollView in Interface Builder which takes up the entire screen of the iPad (0, 0, 1024, 768)
However - when running the app, the scrollView is only displaying on the screen at (0, 0, 1024, 440). The 440 is an estimate, but it is not extending all the way down to fill the screen as it should.
I've done this same thing in other apps and have not encountered this issue.
I've run "Clean" on the project and I've tried deleting the scrollView and recreating it and still the same issue occurs.
I even tried to programmatically reinforce what's in Interface Builder but still it showed up the same way.
CGRect scrollFrame = CGRectMake(0, 0, 1024, 768);
[scrollView setFrame:scrollFrame];
If you have any idea why this may be happening, your help would be GREATLY appreciated.
* UPDATE *
After some more research, there is something wrong with the view controller.
That area at the bottom where the scrollView isn't showing is totally not accessible. If I put a button toward the bottom of the screen, I can't click that button. If it's up in the top half of the screen I can click it just fine.
Also, the scrollview isn't really starting at 0, 0. Where it starts it is missing the top part of the content. So it seems like the scrollView DOES have the height of 768, but is starting at -320 so that the top of it is off the top of the screen and the bottom of it ends before the bottom of the screen.
The issue seems to have been that the app thought it was in Portrait mode even though I had the .xib in Landscape mode.
Fixed it with this little trick in the viewDidLoad of the mainProjectViewController:
CGRect landFrame = self.view.frame;
landFrame.size.width = self.view.frame.size.height;
landFrame.size.height = self.view.frame.size.width;
self.view.frame = landFrame;
Actually, viewing it in landscape mode is just a convenience for you to see what happens if you rotate the device. Launching in landscape mode can be problematic. See this question and its answers for some excellent info.
Related
I have a picker that I have created in my iPhone app, and it runs fine - but the picker is part of an overlay, so some of the values are hard-coded as to how far down and to the left the overlay appears.
So an obvious error occurs when I try and make the comparable iPad version. I opened the iPad storyboard and set everything up, but naturally when I run it, I have the uipickerview appearing in the middle and to the left of the huge iPad screen, wayyy off where it should be.
Is there any way to make an overlay of a picker automatically center and hug the bottom of the screen, no matter what size the screen is, instead of having the location of it hard-coded?
It looks like you'd like the picker to rest at the bottom of the view controller's main view (it's parent, I assume) and be as wide as the view. Try this...
CGRect viewFrame = self.view.frame;
CGRect pickerHeight = self.picker.frame.size.height; // assume you have an outlet called picker
CGRect pickerFrame = CGRectMake(0.0, viewFrame.size.height-pickerHeight,
viewFrame.size.width, pickerHeight);
self.picker.frame = pickerFrame;
I have a really strange problem. I have a UIView and on that view I have 3 UIButtons.
the UIView has a frame
CGRectMake(0, 0, 320, 300)
and I put the buttons on the frame one next to the other with height 50 pixels on the bottom part of the UIView but still within it.
For some reason the UIButtons don't receive the touch but if I raise their height they do...
what could be the cause of this strange problem?
maybe there is a component at the same place with the button with a different zindex
try this mothode to bring your btn to front
[yourView bringSubviewToFront:yourButton]
You may also look into the frame size of the UIButton's parent view. when I started out I often overlooked this and actually what happened is the button is not completely inside the parent. But due to the fact the parent view is not clipping that view I could see it... but not interact with part or all of it.
Try changing CGRectMake(0, 0, 320, 300) to CGRectMake(0, 100, 320, 300) or similar to move the view down the page and compare the behaviour with moving the buttons inside the view.
Does this have the same effect as moving the buttons?
This should help you work out if the problem is within this view, or outside of it.
I have a UIView of size width=320px height=40px which I want to display at the bottom looking like a tab-bar.
I use the following code to accomplish this and it works fine on iPhone. But when I try the iPad simulator, the view does not appear anywhere on the screen.
buttonsView.frame=CGRectMake(
0,
self.view.frame.size.height - buttonsView.frame.size.height,
self.view.frame.size.width,
buttonsView.frame.size.height );
This stretches the view to the width of the screen but keeps it's original height.
How can I make this show right on my iPad also?
[UPDATE]
This happens in my viewDidLoad.
I have this NSLog now:
NSLog(#"buttonsView Width: \t%g\t%g\tHeight:\t%g\t%g",self.view.frame.size.width, buttonsView.frame.size.width, self.view.frame.size.height, buttonsView.frame.size.height);
With output:
iPhone:
buttonsView Width: 320 320 Height: 460 40
iPad:
buttonsView Width: 768 768 Height: 1004 40
I also create another view like this for the top of the page which works fine:
dataView.frame=CGRectMake(
0,
0,
self.view.frame.size.width,
dataView.frame.size.height);
Have you looked (using breakpoints or NSLog) at the values you are putting into the CGRectMake call, just as a sort of "sanity check"?
Thanks for the info. My next thought is that between viewDidLoad and viewWillAppear something is being changed by the OS. Perhaps try moving the code to viewWillAppear so that you are guaranteed the frames you are working with will be the frames that will be displayed. This Stack Overflow answer explains it in a little bit more depth.
This happened because the Auto Resizing was set for the UIView's.
To fix, set the Auto Resizing to bind it to the top left corner. This way whenever you change the frame, it is relative to the top left pixel.
I have an iPhone app. i'm trying to make it universal w/out new xibs. from a UI aspect, my app is fairly simple and straight forward, i just have a a UIImageview and some toolbars.
i'm having an issue where i set my top toolbar to 0, 0 but it is appearing in the middle of my screen when its an iPad.
topToolBar.frame = CGRectMake(0, (-1 * topToolBar.frame.size.height), topToolBar.frame.size.width, topToolBar.frame.size.height);
i initially hide the toolbar and show it if you tap the screen (works properly on iPhone). when i try to set the toolbar hidden on the iPad, its in the middle of the screen. when i nslog the frame, it shows (0, -44, 320, 44) which means it still thinks the screen size is iphone of (480, 320).
the funny part is when i use my tap function to show/hide the toolbar, it behaves properly with a frame of (0, -44, 768, 44).
my hide/show animation block is:
[UIView animateWithDuration:.2
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
topToolBar.frame = CGRectMake(0, (-1 * topToolBar.frame.size.height), topToolBar.frame.size.width, topToolBar.frame.size.height);
}
completion:nil];
its the same code i use to try to initially hide the toolbar. any ideas what is going on?
I would guess it’s an issue with the toolbar’s autoresizing mask. If you’re creating it in Interface Builder, make sure that the strut on the bottom is grayed out and that the ones on the other three sides are highlighted, like this:
If you’re creating the toolbar programmatically, you can just set its autoresizingMask to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin.
I got a UIView with 2 subviews. The UIView is set to UIViewAutoresizingFlexibleWidth. Now when it enters layoutSubviews it resizes the frames of the subviews relative to the UIView like so:
rect.size.width = self.frame.size.width - rect.origin.x - textLabel.frame.origin.x;
But a problem occurs in landscape mode cause in portrait mode the self.frame.size.width (and bounds for that matter) respond 768 at start and 788 after it's done rotating. Meaning when it rotates it seems to add 20pixels which I assume is the status bar.
When I hard code 768 it all works as expected. But I don't want that of course. I could store the initial state into a var and use that but I don't think that's the right way to do it.
Anyone have a solution?
Greetings,
in my application I have been facing the same Problem. To solve it I simply used the didRotateFromInterfaceOrientation:method to resize the View when the device is rotated.self.view.frame = CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
Hope this will help.