一、静态图片的设置
iOS设备现在有三种不同的分辨率:iPhone 320x480、iPhone 4 640x960、iPad 768x1024。以前程序的启动画面(图片)只要准备一个 Default.png就可以了,但是现在变得复杂多了。下面就是 CocoaChina 会员做得总结
如果一个程序,既支持iPhone又支持iPad,那么它需要包含下面几个图片:
Default-Portrait.png iPad专用竖向启动画面 768x1024或者768x1004
Default-Landscape.png iPad专用横向启动画面 1024x768或者1024x748
Default-PortraitUpsIDeDown.png iPad专用竖向启动画面(Home按钮在屏幕上面),可省略 768x1024或者768x1004
Default-Landscapeleft.png iPad专用横向启动画面,可省略 1024x768或者1024x748
Default-LandscapeRight.png iPad专用横向启动画面,可省略 1024x768或者1024x748
Default.png iPhone默认启动图片,如果没有提供上面几个iPad专用启动图片,则在iPad上运行时也使用Default.png(不推荐) 320x480或者320x460
Default@2x.png iPhone4启动图片640x960或者640x920
为了在iPad上使用上述的启动画面,你还需要在info.pList中加入key: UISupportedInterfaceOrIEntations。同时,加入值UIInterfaceOrIEntationPortrait,UIInterfacOrIEntationPortraitUpsIDeDown,UIInterfaceOrIEntationLandscapeleft,UIInterfaceOrIEntationLandscapeRight。
二、设置静态图片停留的时间
在- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions中使用下面集中方法都可以:
1、sleep(3);
2、[NSThread sleepForTimeInterval:5.0];
3、[selfperformSelector:@selector(startupvIEw)withObject:nilafterDelay:3];
三、设置启动动画
在appDelegate中加载启动动画的controller,在开启动画的controller中载入首页controller,通过透明度来设置淡入和淡出。
appDelegate.h
#import <UIKit/UIKit.h>#import "Startupscreen.h"@interface AppDelegate : UIResponder <UIApplicationDelegate> { Startupscreen *startupscreen;}@property (strong,nonatomic) UIWindow *window;@property (nonatomic,retain) Startupscreen *startupscreen;@end
appDelegate.m
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ NSLog(@"dIDFinishLaunchingWithOptions"); self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; startupscreen = [[Startupscreen alloc] initWithNibname:@"Startupscreen" bundle:nil]; [self.window addSubvIEw:startupscreen.vIEw]; [self.window makeKeyAndVisible]; return YES;}
Startupscreen.h
#import <UIKit/UIKit.h>#import "VIEwController.h"@interface Startupscreen : UIVIEwController{ NSTimer *timer; UIImageVIEw *splashImageVIEw; UINavigationController *nav; VIEwController *myvIEwcontroller;}@property (nonatomic,retain) NSTimer *timer;@property (nonatomic,retain) UIImageVIEw *splashImageVIEw;@property (nonatomic,retain) UINavigationController *nav;@property (nonatomic,retain) VIEwController *myvIEwcontroller;@end
Startupscreen.m
#import "Startupscreen.h"#import "VIEwController.h"@interface Startupscreen ()@end@implementation Startupscreen@synthesize timer;@synthesize splashImageVIEw;@synthesize nav;@synthesize myvIEwcontroller;int flag;NSTimer *timer;- (ID)initWithNibname:(Nsstring *)nibnameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibname:nibnameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; // Do any additional setup after loading the vIEw from its nib. CGRect appFrame = [[UIScreen mainScreen] applicationFrame]; UIVIEw *vIEw = [[UIVIEw alloc] initWithFrame:appFrame]; vIEw.autoresizingMask = UIVIEwautoresizingFlexibleHeight|UIVIEwautoresizingFlexibleWIDth; self.vIEw = vIEw; [vIEw release]; flag = 0; splashImageVIEw = [[UIImageVIEw alloc] initWithImage:[UIImage imagenamed:@"c618Default1.png"]]; splashImageVIEw.frame = CGRectMake(0,0,768,1004); [self.vIEw addSubvIEw:splashImageVIEw]; timer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:@selector(addLabel) userInfo:nil repeats:YES]; myvIEwcontroller = [[VIEwController alloc] initWithNibname:@"VIEwController" bundle:nil]; myvIEwcontroller.vIEw.Alpha = 0.0; //[self.vIEw addSubvIEw:myvIEwcontroller.vIEw]; nav = [[UINavigationController alloc] init]; [nav pushVIEwController:myvIEwcontroller animated:NO]; [self.vIEw addSubvIEw:nav.vIEw]; timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO]; }- (voID)addLabel{ flag++; if (flag <=5) { UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(200+50*flag,600,40,40)]; label1.text = @"123"; label1.Font = [UIFont systemFontOfSize:23]; label1.textcolor = [UIcolor whitecolor]; [self.vIEw addSubvIEw:label1]; [label1 release]; } }- (voID)fadeScreen{ [UIVIEw beginAnimations:nil context:nil]; // begins animation block [UIVIEw setAnimationDuration:0.75]; // sets animation duration [UIVIEw setAnimationDelegate:self]; // sets delegate for this block [UIVIEw setAnimationDIDStopSelector:@selector(finishedFading)]; // calls the finishedFading method when the animation is done (or done fading out) self.vIEw.Alpha = 0.0; // Fades the Alpha channel of this vIEw to "0.0" over the animationDuration of "0.75" seconds [UIVIEw commitAnimations]; // commits the animation block. This Block is done.}- (voID) finishedFading{ [UIVIEw beginAnimations:nil context:nil]; // begins animation block [UIVIEw setAnimationDuration:0.75]; // sets animation duration self.vIEw.Alpha = 1.0; // fades the vIEw to 1.0 Alpha over 0.75 seconds myvIEwcontroller.vIEw.Alpha = 1.0; [UIVIEw commitAnimations]; // commits the animation block. This Block is done. for(UIVIEw *mylabelvIEw in [self.vIEw subvIEws]) { if ([mylabelvIEw isKindOfClass:[UILabel class]]) { [mylabelvIEw removeFromSupervIEw]; } } [splashImageVIEw removeFromSupervIEw];}
上述代码实现了一个简单的进度启动动画,供大家参考。
总结以上是内存溢出为你收集整理的iPhone开发之启动画面及动画全部内容,希望文章能够帮你解决iPhone开发之启动画面及动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)