适用于iPhone和iPad的通用应用程序概念 [英] Universal Apps concept for iPhone and iPad

查看:118
本文介绍了适用于iPhone和iPad的通用应用程序概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通用应用程序的菜鸟所以请帮助我,让我知道如果可以做到这一点,我正在创建一个通用的应用程序,为此,我已经编写了代码并在我的每个视图控制器中进行了设置在iPhone和iPad组和运行时我正在识别设备是否其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];
    }

现在查询是我老板正在吃我的脑袋他告诉我,我们可以只写一堂课在运行时,当应用程序将在iphone或ipad设备或模拟器中启动时,视图控制器将相应地调整帧我使用上述方法完成此操作,但他说如果你喜欢这样,那么代码会增加而你必须遭受巨大的头痛,所以实际上他是对的,但没有找到任何替代解决方案,所以在说这不能做之前我想考虑采取一些专家建议

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

推荐答案

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

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.

#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.  */
}

这篇关于适用于iPhone和iPad的通用应用程序概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆