简体   繁体   English

iPhone ipad笔尖返回相同的self.view.frame.size.width问题

[英]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 我用了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 因此,当我在iphone模拟器中运行时,它将返回320,但是,当我在ipad模拟器中运行时,它将仍然返回我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. 我为iphone和ipad使用了不同的nib文件,它们正在获取正确的nib文件,目标家庭是ipad / iphone,它应该返回768,因此我可以根据该尺寸调整图像大小。

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. 但UIScreen并未考虑当前的界面方向。 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? 在iPad Simulator中运行时是否正在使用iPad Nib文件? Maybe you want to check by changing something (maybe, change the location of,say, a button) in the iPad's NIB. 也许您想通过更改iPad的NIB中的某些内容(例如,更改按钮的位置)进行检查。 This way, when the App runs, you can check if it's the iPhone's NIB or iPad's Nib. 这样,当应用程序运行时,您可以检查它是iPhone的NIB还是iPad的Nib。

First you check this:- 首先您检查一下:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) and if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone)和

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)

And also while allocating file:- 并且在分配文件时:

For iPhone:- ABController *controller = [[ABController alloc] initWithNibName:@"ABController~iPhone" bundle:nil]; 对于iPhone:-ABController * controller = [[ABController alloc] initWithNibName:@“ ABController〜iPhone” bundle:nil];

For iPad:- ABController *controller = [[ABController alloc] initWithNibName:@"ABController~iPad" bundle:nil]; 对于iPad:-ABController * controller = [[ABController alloc] initWithNibName:@“ ABController〜iPad” bundle:nil];

Make sure that 确保

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

is set to NO. 设置为NO。

That will do your work 那会做你的工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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