0

我正在将我的应用程序迁移到 iPhone 应用程序到 iPhone 5 分辨率。我从stackoverflow中的其他问题中看到了这一点:

例子:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    // code for 4-inch screen
} else {
    // code for 3.5-inch screen
}

但似乎,我需要为我的所有图像添加此代码。有没有更简单的方法?意思是更通用的方式。

谢谢...

4

5 回答 5

0

Build an app using iOS 6 as the Base SDK and use the Auto Layout feature to make screens that can scale for all type of screens. You'll need Xcode 4.5 to do this. Add a splash image named Default-568h@2x.png

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    switch (interfaceOrientation) {

        case UIInterfaceOrientationPortrait:
        case UIInterfaceOrientationPortraitUpsideDown:
            //[self ArrangeControllsFor_Protrate];
            [self performSelector:@selector(ArrangeControllsFor_Protrate) withObject:Nil afterDelay:0.005f];
            return YES;
            break;
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            [self performSelector:@selector(ArrangeControllsFor_LandScape) withObject:Nil afterDelay:0.005f];
            return YES;
            break;
    }
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    switch (toInterfaceOrientation){

        case UIInterfaceOrientationPortrait:
        case UIInterfaceOrientationPortraitUpsideDown:
            [self performSelector:@selector(ArrangeControllsFor_Protrate) withObject:Nil afterDelay:0.005f];
            break;
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            [self performSelector:@selector(ArrangeControllsFor_LandScape) withObject:Nil afterDelay:0.005f];
            break;
    }
}
-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotate{

    return YES;
}
-(void)ArrangeControllsFor_Protrate{

    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [self.view setBounds:CGRectMake(0, 0, 320,568)];
    [self.view setFrame:CGRectMake(0, 0, 320, 568)];
}

-(void)ArrangeControllsFor_LandScape{

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self.view setBounds:CGRectMake(0, 0, 568, 320)];
    [self.view setFrame:CGRectMake(0, 0,  568, 320)];
}
- (void)viewWillAppear:(BOOL)animated{

    UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if(UIInterfaceOrientationIsPortrait(statusBarOrientation))
    {
        [self ArrangeControllsFor_Protrate];
    }
    else
    {
        [self ArrangeControllsFor_LandScape];
    }
}
于 2013-02-14T09:53:04.213 回答
0

为 UIImage 类创建一个类别。将此逻辑移至 UIImage 类。

现在将现有的 UIImage 创建函数更改为您在类别中创建的函数。

于 2013-02-14T09:06:26.460 回答
0

如果您是注册的 Apple 开发人员,您可以使用 AutoLayout 我推荐您可以从去年的 WWDC 中找到的教程。

于 2013-02-14T09:06:30.937 回答
0

检查并在prefix.h文件中写入

#define IPHONE5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

每当您想检查时,只需检查

if (IPHONE 5) {
     // Code for iPhone 5 Device
      enter code here
} else if (!IPHONE5) {
    // Code for 3.5 inch (iphone 4 nad less)
     enter code here
}
于 2013-02-14T09:28:38.327 回答
0
  1. 首先,您必须创建尺寸为 640 x 1136 和视网膜质量的启动图像。
  2. 然后将图像命名为 Default-568h@2x.png 并将其设置为您的 iphone 应用程序中的启动图像。
  3. 然后你必须设置自动调整大小的蒙版。
  4. 创建您希望与 iPhone 5 屏幕分辨率兼容的所有必需图像。
  5. 在你的 iPhone 5 上运行你的应用程序,一切都应该按要求运行。
于 2013-05-24T09:57:35.180 回答