将应用程序转换为通用后:-
你已经创建了两个不同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
在我编辑答案时进行检查