简体   繁体   中英

iphone ipad nib return same self.view.frame.size.width issue

I would like to get the current dimension of the screen. i used self.view.frame.size.width

NSLog(@"%f",self.view.frame.size.width)

so when I run in the iphone simulator , it will return 320 however, when i run in the ipad simulator, it will still return me 320

I have different nib files for iphone and ipad and they're getting the proper nib files and the target family is ipad/iphone it should return 768 and so i can resize the images according to that.

any ideas?

try and use these

CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenheight = [UIScreen mainScreen].bounds.size.height;

but UIScreen doesn't take into account the current interface orientation. you will have to check for that also

or directly check for the device type

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

and

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

Change your targeted devices to Universal as in this picture

在此处输入图片说明

Is your iPad Nib file being used when running in a iPad Simulator? Maybe you want to check by changing something (maybe, change the location of,say, a button) in the iPad's NIB. This way, when the App runs, you can check if it's the iPhone's NIB or iPad's Nib.

First you check this:-

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) and

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

And also while allocating file:-

For iPhone:- ABController *controller = [[ABController alloc] initWithNibName:@"ABController~iPhone" bundle:nil];

For iPad:- ABController *controller = [[ABController alloc] initWithNibName:@"ABController~iPad" bundle:nil];

Make sure that

 self.view.autoresizesSubviews=NO;
 Imageview.autoresizingMask=NO;

is set to NO.

That will do your work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM