Fil*_*lic 480
[[UIScreen mainScreen] bounds]因为似乎没有特定的API.从iOS 8开始,还有一些大小类可以将屏幕尺寸纵向和横向抽象为常规或紧凑,并且是推荐用于调整UI的方法.San*_*hry 116
如果您有为iPhone 4S或更早版本构建的应用程序,它将在iPhone 5上运行letterboxed.
要使您的应用适应新的更高屏幕,您要做的第一件事就是将启动图像更改为:Default-568h@2x.png.它的大小应该是1136x640(HxW).是的,在新屏幕尺寸中使用默认图像是让您的应用程序占据整个新iPhone 5屏幕的关键.
(请注意,命名约定仅适用于默认图像.命名另一个图像"Image-568h@2x.png"不会导致它被加载代替"Image@2x.png".如果需要加载不同的图像对于不同的屏幕尺寸,您必须以编程方式进行.)
如果你非常幸运,可能就是这样......但很有可能,你将不得不采取更多措施.
在极端情况下(当上述情况都不足时),设计两个Xib并在视图控制器中加载适当的Xib.
要检测屏幕大小:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
}
if(result.height == 568)
{
// iPhone 5
}
}
Run Code Online (Sandbox Code Playgroud)
one*_*ray 30
唯一真正需要做的是将一个名为"Default-568h@2x.png"的启动图像添加到应用程序资源中,一般情况下(如果你足够幸运的话)该应用程序将正常工作.
如果应用程序不处理触摸事件,请确保键窗口具有适当的大小.解决方法是设置正确的框架:
[window setFrame:[[UIScreen mainScreen] bounds]]
Run Code Online (Sandbox Code Playgroud)
迁移到iOS 6时,还有其他与屏幕大小无关的问题.有关详细信息,请阅读iOS 6.0发行说明.
Som*_*Man 22
有时(对于故事前应用程序),如果布局变得非常不同,则值得根据设备指定不同的xib(请参阅此问题 - 您需要修改代码以处理iPhone 5)在viewController中初始化,因为如果您需要不同的图形,任何与自动调整蒙版的混合都不会起作用.
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
NSString *myNibName;
if ([MyDeviceInfoUtility isiPhone5]) myNibName = @"MyNibIP5";
else myNibName = @"MyNib";
if ((self = [super initWithNibName:myNibName bundle:nibBundleOrNil])) {
...
Run Code Online (Sandbox Code Playgroud)
这对于定位较旧iOS版本的应用非常有用.
Man*_*nni 20
在这里你可以找到一个很好的教程(对于MonoTouch,但你也可以使用非MonoTouch项目的信息):http:
//redth.info/get-your-monotouch-apps-ready-for-iphone-5 -ios-6-今天/
为您的启动/默认屏幕(640 x 1136像素)创建一个名为" Default-568h@2x.png " 的新图像
在iOS模拟器中,转到硬件 - >设备菜单,然后选择" iPhone(Retina 4英寸) "
创建其他图像,例如背景图像
public static bool IsTall
{
get {
return UIDevice.currentDevice.userInterfaceIdiom
== UIUserInterfaceIdiomPhone
&& UIScreen.mainScreen.bounds.size.height
* UIScreen.mainScreen.scale >= 1136;
}
}
Run Code Online (Sandbox Code Playgroud)
private static string tallMagic = "-568h@2x";
public static UIImage FromBundle16x9(string path)
{
//adopt the -568h@2x naming convention
if(IsTall())
{
var imagePath = Path.GetDirectoryName(path.ToString());
var imageFile = Path.GetFileNameWithoutExtension(path.ToString());
var imageExt = Path.GetExtension(path.ToString());
imageFile = imageFile + tallMagic + imageExt;
return UIImage.FromFile(Path.Combine(imagePath,imageFile));
}
else
{
return UIImage.FromBundle(path.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
通过XIB迁移iPhone5和iPhone4很容易.........
UIViewController *viewController3;
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
UIViewController *viewController3 = [[[mainscreenview alloc] initWithNibName:@"iphone5screen" bundle:nil] autorelease];
}
else
{
UIViewController *viewController3 = [[[mainscreenview alloc] initWithNibName:@"iphone4screen" bundle:nil] autorelease];
}
Run Code Online (Sandbox Code Playgroud)
小智 10
我添加了新的默认启动图像和(在查看其他几个SE答案...)确保我的故事板都自动调整大小和子视图,但视网膜4英寸仍然是letterboxed.
然后我注意到我的信息plist有一个" 启动图像 " 的行项目设置为" Default.png ",我因此删除了魔法信箱不再出现.希望这可以为其他人节省我所忍受的同样的疯狂.
小智 9
要确定您的应用程序可以支持iPhone 5的Retina使用:(这可能是更强大的恢复显示,4S的Retina等类型,但因为它是写在下面,它只是返回如果iPhone支持iOS5的视网膜作为是还是不是)
在常见的".h"文件中添加:
BOOL IS_IPHONE5_RETINA(void);
Run Code Online (Sandbox Code Playgroud)
在常见的".m"文件中添加:
BOOL IS_IPHONE5_RETINA(void) {
BOOL isiPhone5Retina = NO;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if ([UIScreen mainScreen].scale == 2.0f) {
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 960){
//NSLog(@"iPhone 4, 4s Retina Resolution");
}
if(result.height == 1136){
//NSLog(@"iPhone 5 Resolution");
isiPhone5Retina = YES;
}
} else {
//NSLog(@"iPhone Standard Resolution");
}
}
return isiPhone5Retina;
}
Run Code Online (Sandbox Code Playgroud)
在constants.h文件中,您可以添加以下定义语句:
#define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
#define IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone
#define IS_WIDESCREEN (fabs((double)[[UIScreen mainScreen] bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_5 (!IS_IPAD && IS_WIDESCREEN)
Run Code Online (Sandbox Code Playgroud)
我想,它并不适用于所有情况,但在我的特定项目中,它避免了重复NIB文件:
common.h您可以在某处根据屏幕高度制作这些定义:
#define HEIGHT_IPHONE_5 568
#define IS_IPHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 ([[UIScreen mainScreen] bounds ].size.height == HEIGHT_IPHONE_5)
Run Code Online (Sandbox Code Playgroud)
在您的基本控制器中:
- (void)viewDidLoad
{
[super viewDidLoad];
if (IS_IPHONE_5) {
CGRect r = self.view.frame;
r.size.height = HEIGHT_IPHONE_5 - 20;
self.view.frame = r;
}
// now the view is stretched properly and not pushed to the bottom
// it is pushed to the top instead...
// other code goes here...
}
Run Code Online (Sandbox Code Playgroud)
小智 8
首先创建两个xib并将所有委托,主类附加到xib,然后你可以在你的appdelegate.m文件中 放入下面提到的这种情况
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
self.ViewController = [[ViewController alloc] initWithNibName:@"ViewControlleriphone5" bundle:nil];
}
else
{
self.ViewController = [[ViewController alloc] initWithNibName:@"ViewControlleriphone4" bundle:nil];
}
Run Code Online (Sandbox Code Playgroud)
您可以在程序中的任何位置使用它,这取决于您的要求,甚至在您的ViewController课程中.最重要的是你已经创建了两个xib单独的文件iphone 4(320*480) and iphone 5(320*568)
检查bounds与568将在横向模式下失败.iPhone 5仅在纵向模式下启动,但如果你想支持旋转,那么iPhone 5"check"也需要处理这种情况.
这是一个处理方向状态的宏:
#define IS_IPHONE_5 (CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size, CGSizeMake(640, 1136)))
Run Code Online (Sandbox Code Playgroud)
'preferredMode'调用的使用来自我几小时前读过的另一篇帖子,所以我没有提出这个想法.
在单例类中尝试以下方法:
-(NSString *)typeOfDevice
{
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
return @"Iphone";
}
if(result.height == 568)
{
return @"Iphone 5";
}
}
else{
return @"Ipad";;
}
return @"Iphone";
}
Run Code Online (Sandbox Code Playgroud)
我从来没有遇到任何设备的问题,因为我有一个代码库,没有任何硬编码值.我所做的是将最大尺寸的图像作为资源而不是每个设备使用一个.例如,我会有一个用于视网膜显示,并将其显示为适合方面,因此它将是每个设备上的视图.例如,在运行时决定按钮的框架.为此,我使用专利视图的%值,例如,如果我希望宽度为父视图的一半占父级的50%,同样适用于高度和中心.
有了这个我甚至不需要xibs.
首先显示此图像.在该图像中,您显示Retina 4支持警告,因此单击此警告并单击添加,以便您的Retina 4启动屏幕自动添加到您的项目中.

并在您使用此代码后:
if([[UIScreen mainScreen] bounds].size.height == 568)
{
// For iphone 5
}
else
{
// For iphone 4 or less
}
Run Code Online (Sandbox Code Playgroud)
您可以使用此定义来计算您是否根据屏幕大小使用iPhone 5:
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
Run Code Online (Sandbox Code Playgroud)
然后使用一个简单的if声明:
if (IS_IPHONE_5) {
// What ever changes
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
148708 次 |
| 最近记录: |