适用于 iPhone 和 iPad 的通用应用程序概念

发布于 2024-11-08 15:39:08 字数 628 浏览 5 评论 0原文

我是通用应用程序的菜鸟,所以请帮助我,让我知道这是否可以完成,我正在创建一个通用应用程序,为此我已经编写了代码并在 iPhone 中的每个视图控制器中进行了设置和 iPad 组,在运行时我正在识别设备,无论是 iphone 还是 ipad,我正在使用下面的方法

 if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        myiPad_View *ipadObj = [[myiPad_View alloc]init];
        [self.window addSubview:ipadObj.view];

    }
    else
    {
        myiPhoneView *obj = [[myiPhoneView alloc]init];
        [self.window addSubview:obj.view];
    }

现在问题是我的老板为此而烦恼,他告诉我我们可以只写一个类并在运行时该应用程序将在 iPhone 或 iPad 设备或模拟器中启动,视图控制器将相应地调整帧我已经使用上述方法完成了这一点,但他说如果你这样做,那么代码将会增加,你必须遭受巨大的损失头痛,所以实际上他是对的,但还没有找到任何替代解决方案,所以在说这不能完成之前,我想听取一些专家的建议

am a noob at universal apps so please help me out and let me know if this can be done, I am creating a universal app and for doing this i have written the code and made the settings in each of my view controllers present in the iPhone and iPad group and at runtime i am identifying the device whether its iphone or ipad i am using the below method

 if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        myiPad_View *ipadObj = [[myiPad_View alloc]init];
        [self.window addSubview:ipadObj.view];

    }
    else
    {
        myiPhoneView *obj = [[myiPhoneView alloc]init];
        [self.window addSubview:obj.view];
    }

Now the query is my boss is eating my head for this he is telling me that can we write just one class and at run time when the app will be launched either in iphone or ipad device or simulator the view controller will adjust the frames accordingly i have done this by using the above method but he says if you do like this then the code will increase and you have to suffer a huge headache so actually he is right but haven't found of any alternate solution to this, so before saying this cant be done i thought of taking some expert advice

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃素的狼 2024-11-15 15:39:08

您的上述方法实际上也是我在某些应用程序中确定设备的方法。

事实上,我最近写了一篇关于这个问题的小文章

您还可以使用:

#define IDIOM    UI_USER_INTERFACE_IDIOM()
#define IPAD     UIUserInterfaceIdiomPad
#define IPHONE   UIUserInterfaceIdiomPhone

if ( IDIOM == IPAD ) 
    NSLog(@"Device is iPad.");
else 
    NSLog(@"Device is iPhone or iPod touch.");

if ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] ) 
{
    NSLog(@"Device is an iPod touch");
    /*  same goes for "iPhone", "iPad" etc.  */
}

Your above method is actually how I determine devices in some of my apps as well.

I actually recently wrote a little piece on this issue.

You can also use:

#define IDIOM    UI_USER_INTERFACE_IDIOM()
#define IPAD     UIUserInterfaceIdiomPad
#define IPHONE   UIUserInterfaceIdiomPhone

if ( IDIOM == IPAD ) 
    NSLog(@"Device is iPad.");
else 
    NSLog(@"Device is iPhone or iPod touch.");

or

if ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] ) 
{
    NSLog(@"Device is an iPod touch");
    /*  same goes for "iPhone", "iPad" etc.  */
}
苏辞 2024-11-15 15:39:08

我有 3 组类:

  • 基类:这是共享逻辑所在的位置
  • iPhone 类:iPhone 特定逻辑(包括 UI)位于此处
  • iPad 类:iPad 特定逻辑(包括 UI)位于此处

我在基类中拥有尽可能多的内容,但是对于逻辑分离的时代,拥有不同的类要容易得多。在我看来,挖掘代码寻找异常会很痛苦。

我发现此博客很有帮助(不是我的)

I have 3 sets of classes:

  • base classes: this is where the shared logic goes
  • iPhone classes: iPhone specific logic including UI goes here
  • iPad classes: iPad specific logic, including UI goes here

I have as much as possible in the base classes, but for the times when the logic is separate, it is much easier to have the distinct classes. Digging through the code looking for the exceptions would be a pain, IMO.

I found this blog helpful (not mine)

夕色琉璃 2024-11-15 15:39:08

这不是问题。你必须创建一个通用应用程序。

文件--->新建项目--->windows应用程序

,然后选择一个产品Universal

Its not a problem . you have to create a universal app.

File--->New Project--->windowsapplication

and then choose a product Universal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文