UIScreen bounds versus applicationFrame - ios

Why do I see in some sample code from Apple (such as PhotoScroller) that I should do the following in loadView:
CGRect frame = [[UIScreen mainScreen] bounds];
instead of
CGRect frame = [[UIScreen mainScreen] applicationFrame];
Does it make a difference to get the main screen's frame?

ApplicationFrame is the screen size minus the size of the status bar (if visible), bounds is the screen size regardless of status bar.
So applicationFrame would return CGRectMake(0,0,320,460) assuming your app has the status bar set to be visible, while bounds would return CGRectMake(0,0,320,480) under the same conditions. Those numbers are assuming iPhone/iPod Touch screen sizes.
UIScreen Class Reference

iOS 9 Update
When using the Split View feature on the iPad, applicationFrame returns the size of your app window. bounds always returns the size of the device.

Related

UIScrollView Height and width

I am facing one strange problem, using the below code I am making the UIScrollView to full screen.
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
CGRect scrollFrame = CGRectMake(0, 0, screenWidth, screenHeight);
self.imageHostScrollView.frame = scrollFrame;
NSLog(#"Scroll Height: %f, Width: %f",screenHeight,screenWidth);
The problem I am facing when the iPad is in the Portrait mode, the height will be big and width will be small, instead I am getting height smaller and width bigger (same happens in Landscape mode also).
Portrait mode the value I am getting is
Scroll Height: 768.000000, Width: 1024.000000
In Landscape mode the value I am getting is
Scroll Height: 1024.000000, Width 768.000000
Can anyone help me
The problem is that the way you're setting the self.imageHostScrollView.frame is silly. You are effectively hard-coding assumptions about the screen into the frame of a view — two things that are completely unrelated to one another.
Instead, use auto layout to pin the edges of the scroll view to the edges of the window. That way, whatever the window may do from now on — making no assumptions about what that may be — the scroll view will continue to fill it exactly.

Xcode 6 beta and resizable Iphone: How to get the current Screen Dimensions

I try to make my Views completely dynamic so the Views can fit any Screen Dimensions. At the Moment i get the screen Width and Height for calculation like this:
CGFloat getDisplayHeight() {
CGSize result = [[UIScreen mainScreen] bounds].size;
return result.height;
}
CGFloat getDisplayWidth() {
CGSize result = [[UIScreen mainScreen] bounds].size;
return result.width;
}
The Problem is that the "Resizable Iphone" Emulator always give me a Width of 768 and a Height of 1024 (Like the iPad). It doesn´t matter when i change the Width and Height Values on the Bottom of the Emulator...is there any new Function i can use for better testing?
EDIT:
I´m still not sure how to handle this exactly...At the Moment i calculate the Size of my Subviews in "viewDidLayoutSubviews" because this is the only Method which shows the correct Width and Heigth of the "resizable Iphone Simulator", the Problem is that when i calculate all my Stuff inside this method it gets called every time when i scroll or touch the UI, so it could be the case that it gets called hundreds of times...and when i try to calculate my Views in "ViewDidAppear" its too late and evrything look reallys weird after the recalculation....

How to draw View Controller from the bottom

I am trying to develop an app in Xcode. I am new in Objective C programming but so far I did OK. Today I got my first problem. I am trying to draw a transparent VC (View Controller) from the bottom up but I do not know how I can accomplish this. I know that drawing in iPhone begins from 0,0 coordinates from top left corner going right and down. Is there a way to kind of cheat and draw the VC from the bottom to top 70% covering the screen, just like the tools menu when swipe up on iPhone screen in iOS 7.x.x
Thanks in advance.
Heres one solution:
Create the view as a subview of the main view in this controller.
self.rolloutView = [[UIView alloc]initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, heightYouWant)];
When the user takes the action, call this function
-(void)toggleView:(id)sender
{
__block CGRect frame = self.rolloutView.frame;
// Check if the frame's origin.y is at the bottom of the screen
if(self.rolloutView.frame.origin.y == [[UIScreen mainScreen] bounds].size.height){
// if it is, reduce it by the height of the view you eventually want
frame.origin.y = [[UIScreen mainScreen] bounds].size.height-heightYouWant ;
}
else{
// else push it down again
frame.size.height = [[UIScreen mainScreen] bounds].size.height;
}
[UIView animateWithDuration:.3
animations:^{
self.rolloutView.frame = frame;
}
completion:nil];
}
I have not compiled the code but it should give you the idea on what i am suggesting

How to get iOS device screen height and width [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
IPhone/IPad: How to get screen width programmatically?
How to get orientation-dependent height and width of the screen?
Accounting for the various iOS devices and orientations, what is the simplest approach to getting the current screen resolution, including height and width?
UIScreen is your friend here.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.
Hope it helps you..

Changing the size of UIScreen on rotation

I am making an iPad app that starts out in the portrait orientation but can rotate over to the landscape orientation. In -(void) loadView, I call the function drawView. In drawView, I have this line of code:
CGRect r = [[UIScreen mainScreen] bounds];
The only problem is that it doesn't update itself when I rotate to landscape mode, so it still thinks that the screen is in the vertical orientation and if I want a text view to extend all the across the entire screen, it cuts it off at the 768th pixel, instead of the 1024th pixel. In -(BOOL)shouldAutorotate... I have case UIInterfaceOrientationLandscapeRight: and case UIInterfaceOrientationLandscapeLeft:, and I would have to ideally place CGRect r = [[UIScreen mainScreen] bounds]; under each case, but I don't think that will work. Any suggestions? Thanks for your help!
Edit: I've even tried calling a function with
CGRect r = [[UIScreen mainScreen] bounds];
in it, but it still won't work. I place an NSLog after it and I received a response, so the app is definitely working properly and not crashing, but I am still unable to figure this out. Any ideas? Thanks for your help!
I think your problem could be solved by using the autoresizingMask of UIView;
Does your app happen to rely on plists for configuration? I've seen some apps where you can get landscape but only after you set an orientation key to false.

Resources