I'm currently working on an iPad-specific application.
Since I don't use interface builder, every view element is using CGRectMake with specific numbers for its position and size.
so I was wondering,
if I use the same exact code on iPhone, do these numbers scale accordingly?
or should I re-insert the numbers for all the view elements?
If the latter case, is there any easy way to change it all?
CGRect coordinates are absolute, so your subviews will not automatically scale down to the iPhone. If you run your code on an iPhone, you will see only the upper-left corner of your iPad layout.
You can pretty easily write a helper method to take the original CGRect values and scale them down for the iPhone layout. However, if you're also drawing text you'll need to scale down the font sizes as well (which probably won't work, so you'll still need to deal with the text in a possible not-automated way).
I'm doing essentially the same thing right now, writing a single app that runs on both iPad and iPhone and scales itself in code to the available dimensions. I'm generally setting up the view layouts as a float proportion of the available screen size, and then converting those proportions to CGRect before rendering.
Kudos on not using Interface Builder by the way - IB may be the most ridiculous atrocity I've ever seen in the programming world (even worse than classic ASP, which is saying something).
You'll have to change your numbers for your iPhone app. The points that CGRectMake uses are pixels and don't scale, with the exception of HD devices like the iPhone 4.
Honestly, the iPad is such a different device that your UI probably needs to be heavily modified to take advantage of the extra screen space.
Related
I'm trying to convert an iPhone application to work universally (on both iPhones and iPads). I've managed to get the frame to re-size correctly, but it seems like the bounds (the part the user can actually interact with) isn't re-sizing appropriately with it. So, for instance, a UIWebView will be drawn in the correct dimensions, but I can only interact with it within a smaller confine the size of an iPhone screen.
Any thoughts what's going on?
How are you re-sizing this view? Is it in an xib with autoresizing mask set to properly expand? If so something else is going wrong. I just tried making a sample project with a webview, where the xib is sized for iPhone. I then marked the application as universal, and it runs just fine in the iPad simulator with all areas touchable.
I'm hoping to recursively change every single View in my application to use the iPhone 4 graphics, and change the content scale factor to 2.0, such that it's the zoomed in version of my iPhone application on the iPad by default.
Currently, the iPad starts out in x1 Zoom, which is the 320x480 pixel version displayed on the 1024x768 real estate of the iPad, where the powers that be have declared that they're too cheap to actually invest in an iPad app, instead requesting that we have the application use iPhone retina graphics with a default content scale factor of 2.0
Upon googling and searching stackoverflow it seems my query is unique, though some questions are sort of similar such as -> Problem adapting scale factor for iPad x2 compatibility mode
And the best way to go about doing this remains undocumented, so I hope to implement this 'hack' so to speak in the best most succinct way possible.
If anyone has done this before, please share the code, otherwise I will update this with my own answer once I've figured it out.
The Answer: THIS CANNOT BE DONE.
The iPad will treat the screen as 480x320, even at 2x, so even if you change the contentScaleFactor appropriately and force it to use #2x.png images, you won't get any better resolution.
This is built into the iphone Operating system, only the Jailbroken iPads can get around this. Which isn't an option to consider.
It's easier to just duplicate the target for iPad, and realign the nib files appropriately, and make the app a Universal App.
It's a daft idea, and even if Apple change this in future SDK releases, it won't be backward compatible which again isn't an option, at least for our development team.
I think the best way to do it rules out using nib files.
If you create your views in code, you can easily use conditional code ([[UIDevice currentDevice] userInterfaceIdiom]) and based on that set the scale for the UIView elements.
I have the following problem. My application has a tab bar at the bottom and a simple TextView above. In order to fit well TextView above tab bar I had to resize it (I did it through Interface Builder) - I just set height to 401px (usually I hate to do such things).
Then I have tested application on the simulator, to my surprise everything looked o.k. on both standard iPhone display and Retina display. Since I do not have an iPhone I am wondering if everything would look good on the real device as well.
So, my question is: how to set the UIView size so it follows best practices and, what is more important, GUI looks good on both Retina and older display.
BTW: I know how to deal with icons and graphics to make them look good on Retina and older display, I've read all the relevant stackoverflow posts on the subject :)
Size is same on both standard and retina display. It's measured in points. Number of pixels depends on display density.
Pixel != point.
Look at UIScreen scale property. For standard screen it contains 1.0 and 2.0 for retina (iPhone 4). It can contain different values, even not integers.
If you set size UIImageView size to 100x100, it will have same physical size on standard and retina display. But on retina, it will show you much nicer image, because 100 points contains more pixels.
The units in Interface Builder are now interpreted as points not pixels. Therefore it will look the same on both types of displays. On old displays 1 point equates to 1 pixel. On Retina displays 1 point equates to 2 pixels.
I've written an application for the iPad that I'd now like to get working on the iPhone (a universal application).
At the moment it runs in the iPhone simulator, but the UIKit elements are positioned using pixel positions - so a lot of them are offscreen. Additionally my UIImages are too big, and need to be scaled to fit the iPhone. How do I go about doing this?
Thanks in advance.
Some more information:
If I position a UIImageView using UIBuilder, the image displayed takes up the same ratio of the screen if displayed on the iPad or iPhone. Which is what I want, however I need to do it programatically.
If I create a UIImageView programmatically it will take up a much larger ratio of the screen on the iPhone compared to the iPad.
Edit:
My nib is actually empty apart from a OpenGL view. The OpenGL view is scaling fine.
I do create a few UIKit controls programmatically and this is where the problem is happening.
Probably the easiest way: make two separate xibs (1 for iPad, 1 for iPhone).
Start a new universal project and migrate the curent one into it, it'll take some time, but it'll save you a lot of headaches.
I'm testing one of my iPhone apps on my iPad in "2x" mode, so it stretches everything to double-size. I've noticed that some text appears to be smoother than others. From my (limited) testing, text in a UITextView or UITextField that is being edited (has keyboard focus) is smoother than a plain UILabel hanging out in a view. I'm not sure if it's anti-aliasing in 2x2 pixel blocks still, or just that it uses all the pixels to draw the letters rather than treating them as 2x2 pixel blocks, or something else entirely. From my testing, this appears to be true regardless of font size.
Does anyone know what is going on here?
And, more importantly, is there a way to control this? It looks much better and I'd like to have my plain UILabels drawn this way too! I'm hoping that a future iOS update will allow the iPad to use iPhone 4 "#2x" resources and font drawing when running an iPhone app in 2x mode, that would make them look much better!
Thanks!
iPad's legacy scaling mode obeys CALayer's magnificationFilter property. Use kCAFilterLinear for smoothed/blurry upscaling, and kCAFilterNearest for blocky/crisp upscaling.
Also, if you set the contents property to be a CGImage that is double-sized, QuartzCore will gladly take advantage of the extra resolution.