Reputation: 139
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
Upvotes: 0
Views: 511
Reputation: 41652
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;
}
Upvotes: 1