简体   繁体   English

适用于iPhone5和iPhone4的UIView

[英]UIView for iphone5 and iphone4

I have created a UIView , with two xibs to support to iphone5 and iphone4. 我创建了一个UIView ,其中有两个xibs支持iphone5和iphone4。 The view width is (iphone5 - 470) and (iphone5 - 400). 视图宽度为(iphone5-470)和(iphone5-400)。 I have initialized this view with checking the conditions for iphone5 or iphone4. 我已经通过检查iphone5或iphone4的条件来初始化此视图。 But while running the app, it seems to take the iphone5. 但是,在运行该应用程序时,似乎需要使用iphone5。

CategoryView *puzzleView = [[CategoryView alloc] initWithFrame:CGRectMake(0, startY, levelScrollView.frame.size.width, 190)];
BOOL isiPhone = IS_IPHONE5([[UIScreen mainScreen] bounds].size.height);
if (isiPhone)
{
    puzzleView = [[[NSBundle mainBundle] loadNibNamed: @"CategoryView5"  owner:self options:nil] objectAtIndex:0];
}
else 
{
    puzzleView = [[[NSBundle mainBundle] loadNibNamed: @"CategoryView-iphone"  owner:self options:nil] objectAtIndex:0];
}

The probles lies in this line: 问题在于这一行:

BOOL isiPhone = IS_IPHONE5([[UIScreen mainScreen] bounds].size.height);

No you are just checking wether the size.height is not 0 不,您只是在检查size.height不为0

Change into something like : 变成类似:

BOOL isiPhone = IS_IPHONE5([[UIScreen mainScreen] bounds].size.height > 480.f);

Bout one should not do it like this. 约一个人不应该这样。 Just make one view and let it grow with the screen size is a better option. 仅使一个视图随屏幕尺寸增长是一个更好的选择。 Just incase Apple ever decide to add an other screen size you will not have to change anything in your code. 万一Apple决定增加其他屏幕尺寸,则您无需在代码中进行任何更改。

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

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