给iPhone程序创建Splash欢迎界面

官方SDK最简单的方法

最简单的方法就是做一个全屏的欢迎页的图片,把它命名为Default.png,然后放在Xcode工程的Resource里面。 执行就可以看到你的这个默认图像在程序完全加载之前显示在屏幕上。

但是这个方法有个问题,如果你的程序很快载入了,这个图片会立刻消失,导致还没有看清楚图片上的内容。 而且有些内容虽然程序已经载入了,但是有些程序需要的资源是要从服务器上加载的,所以直接进入程序,用户还是无法使用这个应用。

自定义model view方法

这个方法的大体思路就是创建一个model view,在程序载入完成后调用这个model view,显示其中的图片。当你的资源载入完成后,再完全移除这个model view。 具体方法为:

  1. 随便建立一个iPhone的工程,例如叫Splash。
  2. 在SplashAppDelegate.m中,在applicationDidFinishLaunching方法的最后加入:
    1.  
    2. [viewController showSplash];
    3.  

    以在加载程序完成后,显示欢迎页

  3. 在SplashViewController.h加入以下属性和方法
    1.  
    2. #import <uikit/UIKit.h>
    3.  
    4. @interface SplashViewController : UIViewController {
    5.         IBOutlet UIView *modelView;
    6.  
    7. }
    8.  
    9. - (void) showSplash;
    10. - (void) hideSplash;
    11.  
    12. @end
    13.  

    其中*modelView就是我们要用到的model view,用来显示splash图片的。 另外两个方法是控制显示和隐藏这个splash的

  4. 在SplashController.m加入上面定义的两个方法的实现
    1.  
    2. -(void)showSplash
    3. {
    4.         UIViewController *modalViewController = [[UIViewController alloc] init];
    5.  
    6.         modalViewController.view = modelView;
    7.  
    8.         [self presentModalViewController:modalViewController animated:NO];
    9.  
    10.         [self performSelector:@selector(hideSplash) withObject:nil afterDelay:2.0];
    11.  
    12. }
    13.  
    14. //hide splash screen
    15.  
    16. - (void)hideSplash{
    17.  
    18.         [[self modalViewController] dismissModalViewControllerAnimated:YES];
    19.  
    20. }
    21.  

     

  5. 创建视图
  6. 在Interface builder中给SplashView添加一个view视图,在工具栏里面拖拽一个view视图到Splash VIew中

    view视图

    view视图


    添加view视图

    添加view视图

     

    链接File’s Owner中的modelview到新建的view上

    链接modelview到新建的view上

    链接modelview到新建的view上

     

     

  7. 添加imageView到新建的view上
  8. 拖拽一个imageview到刚建立的view中

    添加imageview

    添加imageview

     

    选中这个imageview,修改其中的image属性为你指定的图片,我这里选择了之前导入的Default.png

    指定图片

    指定图片

     

之后你就可以运行了,应该是2秒后,splash图片自动消失。

http://blog.prosight.me/index.php/2009/06/118

posted @ 2010-10-22 21:52  周宏伟  阅读(1475)  评论(0编辑  收藏  举报