在AppDelegate里,通过获取UIDevice的userInterfaceIdiom属性,可以检测到当前程序是运行在iphone或者是ipad上,分别加载相应的视图,就能在两种设备中正常的运行起来。 例子如下:
UIDevice* device=[UIDevice currentDevice];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if (device.userInterfaceIdiom==UIUserInterfaceIdiomPhone) {
IPhoneViewController* IPhoneViewController1=[[IPhoneViewController alloc]init];
window.rootViewController= IPhoneViewController1;
}
else if (device.userInterfaceIdiom==UIUserInterfaceIdiomPad)
{
IPadViewController* IPadViewController1=[[IPadViewController alloc]init];
window.rootViewController= IPadViewController1;
}
本文介绍了如何在AppDelegate中通过检测UIDevice的userInterfaceIdiom属性来判断当前设备是iPhone还是iPad,并据此加载相应的视图控制器。此方法确保了应用能在两种设备上正常运行且提供适配的用户体验。
4057

被折叠的 条评论
为什么被折叠?



