I wonder if anyone can help me with following. I have written a Quartz 2d ap and have used the following code to get the correct scale factor for each device :
if ([UIScreen instancesRespondToSelector:#selector(scale)])
{
return [[UIScreen mainScreen] scale];
}
else
{
return 1.0;
}
I then multiply all values by this scale mulitplier in my code. The problem I have is that the app does not display propertly in x2 mode on the ipad - everything is two times too big. Can anybody help me ?
Thanks,
Martin
The scale factor is related to the Retina displays on the newer iPhones and iPod touches, not the 2X scaling setting on the iPad. In fact, the UIScreen scale property you are referencing does not exist on the iPad's current 3.2 OS version, only on 4.0+. On the current iPads running the OS 4.2 beta, it should always return 1.0.
The problem you are experiencing with Quartz drawing in the 2X mode must come from somewhere else. Do you do any device-specific checks for any elements in your code?
I am not sure if this is your problem, but you seem to want to test the UIScreen for the selector scale. Which it will never have. That selector works only on [UIScreen mainScreen].
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)])
{
return [[UIScreen mainScreen] scale];
}
else
{
return 1.0;
}
Although, this mistake would let you think that it would always return a scale of 1.0.
Related
Today i am going to create an iphone application which is compatible with iphone4 and iphone5. Earlier i have changed iphone4 application views programetically by using below code to adjust controllers for iphone5.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for iphone5
}
else {
// code for iphone4
}
am thinking this is difficult to track all the frames and sizes of controllers each and every time. I have created one sample app and also tried with Auto-resizing option(i have put check mark) at the starting of view and selected size Retina 4 full screen in inspector. And also selected simulator hardware-device is iphone Retina-4 inch
if i change simulator hardware-device is iphone Retina-3.5 inch then the screen is looking like
My question is without setting frames how can i achieve this problem.
Please help me.
Thanks in advance.
You can use this link for autosizing
http://blog.mugunthkumar.com/coding/supporting-the-iphone-5/
Instead of giving static numbers give frames dynamically. means instead of giving 320 give self.view.frame.size.width so you no need to check the device, just you need to add default splash screen.
You problem could be resolved easily using Autolayout feature provided in the XCode Version 4.x .
Go through the following link :-
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
By applying few contraints using Autolayout your problem could easily be resolved.
Happy Coding :)
I made a game using cocos2d for iPad.. Now I have to scale it for iPhone. I tried using scaleX and ScaleY parameters for my GameScene. It scaled the sprites, but I have a lot of hard coded boundaries for my objects which don't get scaled. How can I do the complete scaling of my game??
you have to do something like following
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[yourview setFrame:CGRectMake(400, 208, viewrect.size.width, viewrect.size.height)];
else
[yourview setFrame:CGRectMake(190, 96, viewrect.size.width, viewrect.size.height)];
you already done for iPad, so now you need to change else portion
set your view's frame there according to device orientation.
I'm starting to convert iPhone App to iPad, the app is a special calculator and has a feel and look like one. on iPhone is to use portrait since it the best fit.
My questions are:
i. when I run it on the iPad do i need to use the whole iPad screen size? I would like just to upscale all my controls size and width by let's say 125% of the original size. How do I check the device screen size and how do I center my calculator to be in the center when running on iPad? currently the iPad is CGRectMake(0,0,640,1024) but it may change in the future.
ii. I also like it to adjust accordingly on both orientations of the iPad but only portrait on the iPhone. and I'm not sure how to do it in the most effective-easy way... if you may advice.
my current iPhone code has .xib with the different controls but I adjust them all using the
-setFrame:CGRectMake(...) in code, so far I set the TARGETED_DEVICE_FAMILY in project settings to run app on both devices but didn't change any of the -setFrame:CGRectMake(...) to be dynamic depending on the device.
TIA
1) You can ask [UIScreen mainScreen] for its bounds - that gives you the size.
2) You need to respond to the rotation methods in your UIViewController related to rotation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
3) You can use this to find out if your app is running on an iPhone or iPad:
[[UIDevice currentDevice] userInterfaceIdiom]
4) To center the view in a larger view use this code:
+ (CGRect)centeredFrameForSize:(CGSize)size inRect:(CGRect)rect
{
CGRect frame;
frame.origin.x = rintf((rect.size.width - size.width)/2) + rect.origin.x;
frame.origin.y = rintf((rect.size.height - size.height)/2) + rect.origin.y;
frame.size = size;
return frame;
}
I get some strange problems when trying to get the screen size in my universal iPhone/iPad app.
I was first using
[[UIScreen mainScreen] bounds]
But it does not return the correct size for iPhone 4 (at least not in the simulator), it just returns 320x480 for all iPhones
Then I changed to
CGSize screenSize = mainscr.currentMode.size;
And it works in the simulator for all apple devices, but when running this line on an iPhone 3GS device the program exits with a SIGABRT
Device is running 3.1.2
Any idea how to get the pixel dimension of the display in a device safe way?
UIScreen.currentMode is not available in < 3.2, so you need to check with -respondsToSelector:
CGSize screenSize;
if ([mainscr respondsToSelector:#selector(currentMode)])
screenSize = mainscr.currentMode.size;
else
screenSize = mainscr.bounds.size;
Similarly, UIScreen.scale is not available in < 4.0, if you use that, check with -respondsToSelector:
.
CGFloat scale = [mainscr respondsToSelector:#selector(scale)] ? mainscr.scale : 1.0f;
[[UIScreen mainScreen] bounds] returns a value in points not in pixels but you can use the scale parameter to convert the resolution in pixels.
The proper way to think about is that the screen resolution IS 320x480 but with a display scale of 2.0. Realize that it is very likely that 'other' apple devices in the future will have other display scales.. imagine for example a new iPad someday that has a scale of 1.5...
if([[UIScreen mainScreen] respondsToSelector:#selector"scale"]) {
displayScale = [[UIScreen mainScreen] scale]; }
The reason they did this is to make it easy to write apps that work on any device. You can put an object on the screen at 100,100 and it will be in the same place on both devices. Use the #2x naming method to provide two sets of images, one at 1x scale and one at 2x scale.
Could someone tell me why the following code would return Screen Size: 320.000000, 480.000000 on the iPhone 4?
CGRect screenRect = [[UIScreen mainScreen] bounds];
NSLog(#"Screen Size: %f, %f", screenRect.size.width, screenRect.size.height);
That method returns a size in Points, not Pixels. If you are a registered apple developer, I would suggest watching the WWDC (new) video on designing for the Retina display. It has a load of really useful information.
UIKit uses points, however OpenGL uses pixels. UIViews now have a contentScaleFactor property, which will be 2 on iPhone 4, and 1 on everything else so far...