当前位置: 代码迷 >> Iphone >> iPhone开场动画片及初始化带有导航(UINavigationController)的标签栏控制器(UITabBarController)
  详细解决方案

iPhone开场动画片及初始化带有导航(UINavigationController)的标签栏控制器(UITabBarController)

热度:412   发布时间:2016-04-25 06:26:58.0
iPhone开场动画及初始化带有导航(UINavigationController)的标签栏控制器(UITabBarController)
    很多程序需要开场动画,但仅仅用Default.png又满足不了自己的需求,如时间太短.解决其最好的办法就是加一个ViewController,我这起名为OpeningViewController.

   在AppDelegate.h里面声明:
    OpeningViewController *openingViewController;...    @property (nonatomic, retain) OpeningViewController *openingViewController;


    在AppDelegate.m中如下:
- (void)applicationDidFinishLaunching:(UIApplication *)application {   	if(openingViewController == nil)		openingViewController = [[OpeningViewController alloc] initWithNibName:@"OpeningViewController" bundle:nil];		[window addSubview:openingViewController.view];		[window makeKeyAndVisible];	NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];	[self performSelectorInBackground:@selector(removeOpeningView) withObject:nil];	[pool release];	return YES;}-(void) removeOpeningView{	NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];	[NSThread sleepForTimeInterval:3];	//[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];	[self setupUI];		[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];	[pool release];	}


   在-(void) setupUI;中设置界面的UI.我这里是初始化一个带有导航(UINavigationController)的标签栏控制器(UITabBarController),如下:
-(void) setupUI {	UIColor *titleBarColor=[UIColor colorWithRed:0.0/255.0 green:173.0/255.0 blue:238.0/255.0 alpha:1.0];		//TabBar Item 1	mainDirectoryViewController = [[MainDirectoryViewController alloc] initWithNibName:@"MainDirectoryViewController" bundle:nil];	if (mainDirNavController == nil)		mainDirNavController = [[UINavigationController alloc] initWithRootViewController:mainDirectoryViewController];	mainDirNavController.navigationBar.tintColor = titleBarColor;	//TabBar Item 2	bookmarkViewController = [[BookmarkViewController alloc] initWithNibName:@"BookmarkViewController" bundle:nil];	if (bookmarkNavController == nil)		bookmarkNavController = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];	bookmarkNavController.navigationBar.tintColor = titleBarColor;		//TabBar Item 3	aboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];	if (aboutNavController == nil)		aboutNavController = [[UINavigationController alloc] initWithRootViewController:aboutViewController];	aboutNavController.navigationBar.tintColor = titleBarColor;	UITabBarItem *customItem1 = [[UITabBarItem alloc] initWithTitle:@"学习" image:[UIImage imageNamed:@"some.png"] tag:0];	UITabBarItem *customItem2 = [[UITabBarItem alloc] initWithTitle:@"书签" image:[UIImage imageNamed:@"some.png"] tag:1];	UITabBarItem *customItem3 = [[UITabBarItem alloc] initWithTitle:@"关于" image:[UIImage imageNamed:@"some.png"] tag:2];		mainTabBar = [[UITabBarController alloc] init];	mainTabBar.delegate = self;	mainTabBar.viewControllers = [NSArray arrayWithObjects:mainDirNavController, bookmarkNavController, aboutNavController, nil];	mainDirNavController.tabBarItem = customItem1;	bookmarkNavController.tabBarItem = customItem2;	aboutNavController.tabBarItem = customItem3;	[customItem1 release];	[customItem2 release];	[customItem3 release];		[window addSubview:mainTabBar.view];}
  相关解决方案