iphone--启动界面的制作

第一种方式 

在iphone的启动应用之前,系统会默认在Resources文件夹中的Default.png,为启动界面。
为了在iPad上使用上述的启动画面,你还需要在info.plist中加入
key: UISupportedInterfaceOrie
ntations。

同时,加入值
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight。
如果觉的启动界面时间比较短,也可以加入下面代码控制一下:
代码如下;
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
  [NSThread   sleepForTimeInterval:3];
returnYES;
}


加上动画

  1. 原理:  
  2. 添加一张和Default.png一样的图片,对这个图片进行动画,从而实现Default动画的渐变消失的效果。  操作:  
  3. 在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中添加如下代码:   // Make this interesting.
  4.     UIImageView *splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];      splashView.image = [UIImage imageNamed:@"Default.png"];  
  5.     [self.window addSubview:splashView];      [self.window bringSubviewToFront:splashView];  
  6.     [UIView beginAnimations:nil context:nil];      [UIView setAnimationDuration:2.0];  
  7.     [UIView setAnimationTransition:UIViewAnimationTransitionNone forView: self.window cache:YES];      [UIView setAnimationDelegate:self];   
  8.     [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];      splashView.alpha = 0.0;  
  9.     splashView.frame = CGRectMake(-60, -85, 440, 635);      [UIView commitAnimations];  
  10. 就ok了  

iphone项目的启动界面尺寸设为320x480,系统自带的,进行加载。


自定义的显示页面

//PRPSplashScreenDelegate.h
@class PRPSplashScreen;
@protocol PRPSplashScreenDelegate<NSObject>
@optional
- (void)splashScreenDidAppear:(PRPSplashScreen*)splashScreen;
- (void)splashScreenWillDisappear:(PRPSplashScreen*)splashScreen;
- (void)splashScreenDidDisappear:(PRPSplashScreen*)splashScreen;
@end
//PRPSplashScreen.h
#import "PRPSplashScreenDelegate.h"
@interface PRPSplashScreen : UIViewController {}
@property (nonatomic, retain) UIImage*splashImage;
@property (nonatomic, assign) BOOLshowsStatusBarOnDismissal;
@property (nonatomic, assign) IBOutletid<PRPSplashScreenDelegate>delegate;
- (void)hide;
@end


//PRPSplashScreen.m
#import "PRPSplashScreen.h"
@implementation PRPSplashScreen
@synthesize splashImage;
@synthesize showsStatusBarOnDismissal;
@synthesize delegate;
- (void)dealloc {
    [splashImagerelease], splashImage = nil;
    [superdealloc];
}
- (void)viewDidUnload {
    [superviewDidUnload];
   self.splashImage = nil;
}
- (void)loadView {
    UIImageView *iv= [[UIImageView alloc] initWithImage:self.splashImage];
   iv.autoresizingMask = UIViewAutoresizingFlexibleWidth| 
      UIViewAutoresizingFlexibleHeight;
    iv.contentMode= UIViewContentModeCenter;
    self.view =iv;
    [ivrelease];
}
- (UIImage *)splashImage {
    if (splashImage== nil) {
       self.splashImage = [UIImageimageNamed:@"Default.png"];
    }
    returnsplashImage;
}
- (void)hide {
    if(self.showsStatusBarOnDismissal) 
{
       UIApplication *app =[UIApplication sharedApplication];
       [app setStatusBarHidden:NOwithAnimation:UIStatusBarAnimationFade];
    }
    [selfdismissModalViewControllerAnimated:YES];
}
- (void)viewDidAppear:(BOOL)animated {
    [superviewDidAppear:animated];
    SELdidAppearSelector = @selector(splashScreenDidAppear:);
    if([self.delegate respondsToSelector:didAppearSelector]) {
       [self.delegatesplashScreenDidAppear:self];
    }
    [selfperformSelector:@selector(hide) withObject:nil afterDelay:0];
}
- (void)viewWillDisappear:(BOOL)animated {
    [superviewWillDisappear:animated];
    if([self.delegaterespondsToSelector:@selector(splashScreenWillDisappear:)]) {
       [self.delegatesplashScreenWillDisappear:self];
    }
}
- (void)viewDidDisappear:(BOOL)animated {
    [superviewDidDisappear:animated];
    if([self.delegaterespondsToSelector:@selector(splashScreenDidDisappear:)]) {
       [self.delegatesplashScreenDidDisappear:self];
    }
}
@end




//AppDelagate.h
#import "PRPSplashScreen.h"
@interface AppDelegate_iPhone : NSObject<UIApplicationDelegate,PRPSplashScreenDelegate> {}
@property (nonatomic, retain) IBOutlet UIWindow*window;
@property (nonatomic, retain) IBOutletUINavigationController *navController;
@property (nonatomic, retain) IBOutletPRPSplashScreen *splashScreen;


@end


//AppDelagate.m
#import "AppDelegate_iPhone.h"
#import "PRPSplashScreen.h"
@implementation AppDelegate_iPhone
@synthesize window;
@synthesize navController;
@synthesize splashScreen;


#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication*)application 
      didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [self.windowaddSubview:self.navController.view];
   self.splashScreen.showsStatusBarOnDismissal = YES;
   self.splashScreen.modalTransitionStyle =UIModalTransitionStyleFlipHorizontal;
   [self.navController presentModalViewController:splashScreenanimated:NO];
    [self.windowmakeKeyAndVisible];
    return YES;
}
- (void)splashScreenDidAppear:(PRPSplashScreen*)splashScreen {
   NSLog(@"splashScreenDidAppear!");
}
- (void)splashScreenWillDisappear:(PRPSplashScreen*)splashScreen {
   NSLog(@"splashScreenWillDisappear!");
}
- (void)splashScreenDidDisappear:(PRPSplashScreen*)splashScreen {
   self.splashScreen = nil;
}
- (void)dealloc {
    [windowrelease], window = nil;
    [navControllerrelease], navController = nil;
    [splashScreenrelease], splashScreen = nil;
    [superdealloc];
}


原文地址:http://www.cocoachina.com/bbs/read.php?tid=73570&page=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值