简体   繁体   English

将iPhone应用程序转换为通用二进制文件

[英]Convert iPhone app to universal binary

I have an iPhone game and I want to convert the project into a universal one. 我有一个iPhone游戏,我想将该项目转换为通用游戏。 In fact, I have done so already by adjusting the target. 实际上,我已经通过调整目标做到了。 The problem is: For example the UIButtons don't resize and don't relocate. 问题是:例如,UIButton不会调整大小,也不会重新放置。

Question: What is the correct way to create a button so that it automatically adjusts its size if the universal app is run on the Pad? 问题:如果在Pad上运行通用应用程序,那么创建按钮以使其自动调整其大小的正确方法是什么?

At the moment I'm making buttons like so: 目前,我正在像这样制作按钮:

    [self setSettingsButton:[UIButton buttonWithType:UIButtonTypeCustom]];
    [settingsButton setFrame:CGRectMake(38, 121, 30, 180)];
    [settingsButton setBackgroundImage:[UIImage imageNamed:@"SettingsButton.png"] forState:UIControlStateNormal];
    [settingsButton addTarget:self action:@selector(prefButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:settingsButton];

Well yes, obviously, the positions and sizes are absolute when they should be relative but my question is: how to make them relative ? 是的,很明显,位置和大小在应该相对时是绝对的,但我的问题是: 如何使其相对

Many thanks for your help! 非常感谢您的帮助!

I see two ways in this situation: 在这种情况下,我看到两种方法:

1) 1)

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    [settingsButton setFrame:CGRectMake(38, 121, 30, 180)];
}
else {
    [settingsButton setFrame:CGRectMake(131, 145, 60, 250)]; // your iPad values
}

2) 2)

CGRect bounds = self.view.bounds; // Here we get VC views frame size
CGRect buttonFrame = CGRectZero;
buttonsFrame.origin.x = bounds.size.width * 1.0/3.0;   // Yours calculations
buttonsFrame.origin.y = bounds.size.width * 4.0/5.0;   //
buttonsFrame.size.width = 240;                         //
buttonsFrame.size.height = 300;                        //
[settingsButton setFrame:buttonsFrame];

Hope this'll help! 希望这会有所帮助!

You can go the if/else route zapko suggests or you can set the main window for each device in the project settings. 您可以按照zapko建议的if / else路线进行操作,也可以在项目设置中为每个设备设置主窗口。 This will at least allow you to isolate the code for the device outside an if/else block and in my experience it is cleaner to maintain. 这至少将使您能够将设备代码隔离在if / else块之外,以我的经验,它更易于维护。

Have you also accounted for the Retina display? 您是否也考虑了视网膜显示屏? I would think the same issue would hit when you test on the standard display vs. the Retina display as well. 我认为在标准显示器和Retina显示器上进行测试时,也会遇到相同的问题。 Since you are creating a game this may not be an option, but adding the buttons to your view via IB will give the app the ability to scale across screens. 由于您正在创建游戏,因此这可能不是一个选择,但是通过IB将按钮添加到视图中将使该应用能够跨屏幕扩展。

最好为iphone和ipad进行设计是最佳选择。否则,必须检查设备是iphone还是ipad([UIDevice currentDevice] .model),然后为两者设置框架

if ([UIDevice currentDevice].model == iPhone) {
    [settingsButton setFrame:CGRectMake(38, 121, 30, 180)];
}
else {
    [settingsButton setFrame:CGRectMake(131, 145, 60, 250)];
}

or 要么

create a universal app you have to design for both iphone page as well as ipad page. 创建您必须为iphone页面和ipad页面设计的通用应用程序。

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

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