2011年5月29日 星期日

建立universal view的基本方法

記錄一下在iOS上建立universal版面的方法 0. 新建一個ipad用的spilt-view專案: xx.proj
預設為xxAppDelegate.h
1. 建立一個全新的xib: A.xib
2. 建立物件
在A.xib中,加入window, object(設定為xxAppDelegate)
3. 拉關連:
A.xib的File's Owner:class指定為xxAppDelegate
拉delegate為xxAppDelegate
B. 到objects的xxAppDelegate, 把window拉到畫面中的window上

4. 測試
建立一個iphone用的xib,: vc_b
修改xxAppDelegate.m
加入
-(bool) isIpad
{
BOOL iPad = NO;
#ifdef UI_USER_INTERFACE_IDIOM
iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#endif
return iPad;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([self isIpad] == TRUE) {
self.window.rootViewController = self.splitViewController;
} else {
RootVC_ip *rootVC=[[RootVC_ip alloc] initWithNibName:@"RootVC_ip" bundle:nil];
self.window.rootViewController = rootVC;
}
[self.window makeKeyAndVisible];
return YES;
}

沒有留言: