我正在将我的应用程序迁移到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
}
但似乎,我需要为我的所有图片添加此代码。有更简单的方法吗?意思是一种更通用的方式。
...谢谢
答案 0 :(得分:0)
为UIImage类创建一个类别。 将此逻辑移至UIImage类。
现在使用您在类别中创建的UIImage创建函数更改现有的UIImage创建函数。
答案 1 :(得分:0)
如果您是注册的Apple开发人员,可以使用AutoLayout我推荐您可以在去年的WWDC上找到的教程。
答案 2 :(得分: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
}
答案 3 :(得分:0)
使用iOS 6构建应用程序作为基本SDK,并使用自动布局功能制作可以扩展所有类型屏幕的屏幕。你需要Xcode 4.5才能做到这一点。添加名为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];
}
}
答案 4 :(得分:0)