小编典典

iOS检测用户是否在iPad上

swift

我有一个可以在iPhone和iPod Touch上运行的应用程序,可以在Retina
iPad上运行,但所有其他操作都需要进行一次调整。我需要检测当前的设备是否为iPad。我可以使用什么代码来检测用户是否正在使用iPad
UIViewController,然后进行相应更改?


阅读 390

收藏
2020-07-07

共1个答案

小编典典

有很多方法可以检查设备是否为iPad。这是我最喜欢的检查设备是否实际上是iPad的方法:

if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
    return YES; /* Device is iPad */
}

我的使用方式

#define IDIOM    UI_USER_INTERFACE_IDIOM()
#define IPAD     UIUserInterfaceIdiomPad

if ( IDIOM == IPAD ) {
    /* do something specifically for iPad. */
} else {
    /* do something specifically for iPhone or iPod touch. */
}

其他例子

if ( [(NSString*)[UIDevice currentDevice].model hasPrefix:@"iPad"] ) {
    return YES; /* Device is iPad */
}

#define IPAD     (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
if ( IPAD ) 
     return YES;
2020-07-07