What do I need to do to run in full resolution? No matter what I do,
UIScreen.MainContent.Bounds => {1024x768}
I am running Monodevelop 2.8.8.4 and I am setting my Deployment Target to 5.1
Any Ideas?
Thanks
Can't verify this since I don't have an iPad3, but on iPhone4's retina display bounds does not tell the whole story.
You need to take scale into consideration too;
CGRect bounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize realSize =
CGSizeMake(bounds.size.width * scale, bounds.size.height * scale);
That would most likely translate to multiplying width and height by UIScreen.MainScreen.Scale on MonoTouch.
Related
Previous i am using Xcode 6.4 or below, In that I didn't notify this type issues. but now I am getting noticeable problems in Xcode 7.2 in related CGRectMake x,y Position.
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
UIView *smallView=[[UIView alloc]initWithFrame:CGRectMake(screenWidth/2, screenHeight/2, 100, 100)];
smallView.backgroundColor=[UIColor redColor];
[self.view addSubview:smallView];
NSLog(#"%f",smallView.frame.origin.x);// 137.500000
above snip code, the position of x & y not perfect. the below image is output .
but if i add center=self.view.ceter It will come to center. the output is
smallView.center=self.view.center;
the problem is , in both case x & y position values same ,
NSLog(#"%f\n%f\n%f\f%f ",screenWidth/2,screenHeight/2,self.view.center.x,self.view.center.y);
Why they will show different result, how can i do without using center property. or Shall go for Autolayout .
on any other device we use this code to set all views in landscape and everything fits great :
float width=[UIScreen mainScreen].bounds.size.width;
float height= [UIScreen mainScreen].bounds.size.height;
on the iPad 2 only , in order to make it work on landscape we have to swap the width and height, otherwise he puts views on portrait and they seems ugly.
Why is it happens only in iPad2 ?
It's not linked to the device but to iOS. Since iOS 8.0, the bounds is now dependent of the device orientation. I'm also swapping width and height like this :
CGRect ScreenBounds() {
CGRect bounds = [UIScreen mainScreen].bounds;
CGRect tmp_bounds = bounds;
if(bounds.size.width < bounds.size.height) {
bounds.size.width = tmp_bounds.size.height;
bounds.size.height = tmp_bounds.size.width;
}
return bounds;
}
Don't size your views relative to the screen, but relative to their container view. Simple as that.
I had same issue From iOS 8 UIScreen is interface oriented so you will get proper results on devices which are running on iOS 8.
In order to support iOS 7 as well you can use following util method:
+ (CGSize)screenSize {
CGSize screenSize = [UIScreen mainScreen].bounds.size;
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
return CGSizeMake(screenSize.height, screenSize.width);
}
return screenSize;
}
I put this code in my app:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
NSLog(#"screenWidth : %f", screenWidth);
NSLog(#"screenHeight : %f", screenHeight);
The I start the simulator with Iphone 3.5 inch.
The log prints 320.000000 for the width.
However, when I then change the device for the simulator, selecing 4inch, it stills shows the same width. Why? Whats wrong. It is supposed to be 640 px in width for Iphone 4 and above, doesnt it?
In the simulator screenWidth will be always 320 ( right now iphone4-5 ). You can check the scale with [[UIScreen mainScreen] scale];
scale will be 2.0 if you running on retina iPhone.
According to the Apple Docs, that value is the "default logical value". If you want to know the actual size, take a look at [[UIScreen mainScreen] scale]. For retina devices, this value is 2.0, so do [[UIScreen mainScreen] bounds].size.width * [[UIScreen mainScreen] scale]
no the width is always 320 POINTS / DPIs -- what you mean is that it really has 640 PIXELS (which are device dependant)
Calculations are always based on device INDEPENDENT points
UIScreen offers a scalingFactor that translates dpi <> pixels
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..
I want to get the width and height of the screen, with this code ...
float screenWidth = [UIScreen mainScreen].bounds.size.width;
float screenHeight = [UIScreen mainScreen].bounds.size.height;
NSLog(#"%f %f",screenWidth, screenHeight);
I get always 320 480 , but these aren't the true measures of the simulator. Now I'm testing on a retina simulator with more resolution, but i always get 320 480
I think your answer can be found here: in iPhone App How to detect the screen resolution of the device
Its the scale that interests you as well. Use CGFloat screenScale = [[UIScreen mainScreen] scale]; to find out the scale.
When positioning elements your points should always be in non-retina scale. Size of the screen for 3.5 inch is 320x480 units and 320x568 for the 4 inch screen. The pixel resolution is times two for retina screens.