将应用转换为通用后:-
您创建了两个具有相同自定义类的不同XIB。如下图:-
iphone->xib-选择文件所有者
现在为 Ipad ite 名称 PhotoViewController_ipad 创建新的 xib。现在只需打开它新创建的XIB-->单击文件所有者--->看起来像:-
其右侧的自定义类空白放在那里 PhotoviewCintroller
并将文件所有者连接到 View
现在你有两个 Xib,一个用于 Iphone,另一个用于 Ipad,现在你可以通过使用如下编码方式来实现这一点:-
在 Delegate.m 文件中加载应用程序时,您需要检查它的 Iphone 或 Ipad:-
#define isiPhone (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE
yourApplicationAppDelegate.h 类
#import <UIKit/UIKit.h>
@class PhotoViewController;
@interface yourApplicationAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) PhotoViewController *viewController;
@end
yourApplicationAppDelegate.m 类
#import "yourApplicationAppDelegate.h"
#import "PhotoViewController.h"
#define isiPhone (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
@implementation yourApplicationAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if (isiPhone) {
if (isiPhone5)
{
self.viewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController_iphone5" bundle:nil];
}
else
{
self.viewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController_iphone" bundle:nil];
}
}else{
self.viewController = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController_ipad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
编辑
另一种想法是,如果您还为 iphone5 编码,那么您也可以检查
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE 我编辑了我的答案