Game Center view cut off on iPhone 5 - iphone

I'm updating an older project to support the iPhone/iPod 5's 4 inch screen. I've added the Default-568h#2x.png to my project, and almost everything seems fine, except:
the Game Center overlay (view controller) is cut off at the bottom.
Tweet sheet popups aren't full width.
Touch input isn't being received on the right/bottom side of the screen.
Seems like my window isn't the correct length.
(I'm going to propose a solution, but I'd like some feedback as to whether or not this is a safe (or "correct") solution.)

I've manually edited my MainWindow.xib file, changing the NSFrameSize from {320, 480} to {320, 568}, which has solved the apparent problem.
This doesn't seem to be causing problems on older/smaller screens, but I'm wondering if this is the best across-the-board solution...

shouldn't you get the current screen size as in the height using following and then use it
instead of changing it manually
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

Related

iPhone App Size Compatibility

I'm making an iPhone app, and I'm using storyboard for the majority of the UI. I'm using xCode 4.6 for iOS 6.
Is there a way to make the app work for both iphone4 size and iphone5 sizes?
When I run the app on the iPhone 4 simulator it doesn't look like it's supposed to - the UI elements don't look like they do on the storyboard (which I'm assuming uses the iPhone5 size).
Let me know if you need more info.
You can dynamically access the height of the view and the device, and then make adjustments based on those values. Alternatively, you could use iOS 6's constraints to set a margin between the bottom of the device or between other elements.
To achieve the former, just access the height property of the view:
CGFloat height = [[self view] frame].size.height;
You can also get the height of the device's screen like so:
CGFloat deviceHeight = [[UIScreen mainScreen] bounds].size.height;
deviceHeight -= 20; // remove the tab bar
deviceHeight -= 44; // remove height for a navigation bar?
Now imagine adjust your view's origin based on this value. You can make it hug the bottom of the device, no matter which one you're on.
[aView setFrame:CGRectMake(10, deviceHeight - 10 - 100, 300, 100)];
If you're unable to adjust the layout of the elements, consider using a scroll view as well. Just set the frame using the techniques above, and then set the content size. On smaller devices, you'll be able to scroll to see more content whereas on larger devices, it will all be right there.

view size on iphone 5 screen incorrect

I am using in my app the view size to position a subview in code.
for example like this:
self.view.bounds.size.height
This subview has to be animated in and out of the view.
This has worked perfect on older devices, now I am trying to support iphone 5 and found out that I still get the height of the old devices.
Everything except this animated view adapts perfect for iphone 5.
The only way to get the right size is if I change the size of the view in the xib, downside is
that if I now run my app on iPhone 4 the view size is the 4inch view size.
What is the problem here?
Or is this the way it is supposed to be and I have to create an extra xib file for iPhone 5?
Alright so the answer is the following:
Like #mrwalker said make sure that the view automatically or programmatically resizes.
And be aware of the fact that the view is not yet resized in the viedDidLoad method.
(This was my mistake)
If you need the resized views size do your stuff in viewWillAppear there the view has already the right size.
thanks to #mrwalker and #AndyDev
You need to make sure your view is resized for the device it's running on. You could either:
Create a new Xib for the iPhone 5, as you might for an iPad
Have existing Xib automatically or programatically resize
I would only opt for (1) if you were intending on having a different layout (more / fewer buttons and such).
How you achieve (2) depends on whether you're using iOS 6's Auto Layout or the old autoresize model. Both methods can be controlled in the Utilities > Size Inspector in Xcode, or programatically.
If you have a single view & view controller, allowing the view to automatically resize to the parent window should be enough.
I had a similar issue where I wasn't getting the correct height and using the Autolayout / autoresize didn't achieve the desired effect. I used the following code to determine the screen size and made the changes based on this.
if ([[UIScreen mainScreen] respondsToSelector: #selector(scale)]) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
// iPhone 5 (1136px height)
} else {
// Not iPhone 5
}
}

UIScrollView height adjusts from IB

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.

When I load a new view in Cocoa Touch, it shifts everything up about 20 pixels

Ok so as seen in this picture progression, I have a home screen with a button named "Songs" on it. When this is pressed, it loads a new Nib and .h and .m files as seen in the middle picture. Then the back button brings us back to the home menu.
The problem is when I load that new view it shifts everything up 20 pixels (around how much the status bars are). Does anyone have any idea why this is. Let me know. I can provide code too.
I've had this problem before. The only way I could remedy it was to set each new view I created to the size of the screen. Here's how I did it:
CGRect fullFrame = [[UIScreen mainScreen] applicationFrame];
self.view.frame = fullFrame;
The problem is probably that wantsFullScreenLayout is set to YES somewhere. Check your UIViewControllers.
You're probably adding the view to the window with the frame (0,0, 320,460). So add 20 pixels to the y coordinate. The better choice would be using the UIViewController instead.

iPad frame width and height mixup in landscape

I have done what this question said here: Landscape Mode ONLY for iPhone or iPad
but the view.frame.size.height is still 1024, which is the height when the device is in portrait, surely when the interface rotates the width and height switch values?
(say you wanted to split the screen into 3 views, for an app that is both landscape and portrait, and you did view.frame.size.width / 3 , in landscape that wouldn't be correct as the width value wouldn't actually be the width)
I'm sure on the iPhone the width and height switch, so why not on the iPad?
This has struck me again I 'm not working with a nib either, could someone please give an acceptable answer? (ie one that doesn't involve manually switch the width and height)
Once the bounty has been awarded to an answer, I will then start another bounty for 250 and award it to the same person.
You haven't specified which "view" you're querying. Assuming this is the top level subview of the window:
You should query the view's bounds not its frame. frame is in the coordinate in which the view is defined (the outside world) hence may remain constant as you rotate. bounds is the coordinate used "inside" the view and for its subviews. This does change when you rotate.
+ (int) currentWidth
{
UIScreen *screen = [UIScreen mainScreen];
int width = screen.currentMode.size.width;
int height = screen.currentMode.size.height;
return (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))? MAX (width, height) : MIN (width, height);
}
I spent a while trying to work out the simplest solution to a frustrating problem, and this was the best I could come up with. Hope it can help.