您的位置:首页 > 其它

iphone--启动界面的制作

2012-03-06 23:13 330 查看
第一种方式

在iphone的启动应用之前,系统会默认在Resources文件夹中的Default.png,为启动界面。

为了在iPad上使用上述的启动画面,你还需要在info.plist中加入

key: UISupportedInterfaceOrie

ntations。

同时,加入值

UIInterfaceOrientationPortrait

UIInterfaceOrientationPortraitUpsideDown

UIInterfaceOrientationLandscapeLeft

UIInterfaceOrientationLandscapeRight。

如果觉的启动界面时间比较短,也可以加入下面代码控制一下:

代码如下;

- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

[NSThread sleepForTimeInterval:3];

returnYES;

}

加上动画

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

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

自定义的显示页面

[b]//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];

}

[/b]

原文地址:http://www.cocoachina.com/bbs/read.php?tid=73570&page=1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: