博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios开发之启动画面及动画
阅读量:6682 次
发布时间:2019-06-25

本文共 5543 字,大约阅读时间需要 18 分钟。

iOS设备现在有四种不同的分辨率:iPhone 320x480iPhone4 640x960、iphone5 1136x640、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

三、设置启动动画

在appDelegate中加载启动动画的controller,在开启动画的controller中载入首页controller,通过透明度来设置淡入和淡出。

appDelegate.h

#import 
#import "Startupscreen.h"@interface AppDelegate : UIResponder
{ 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 
#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];}

上述代码实现了一个简单的进度启动动画,供大家参考。

 

转自:

转载地址:http://fbxao.baihongyu.com/

你可能感兴趣的文章
技巧: iPhone玩游戏手机发烫?有妙招
查看>>
标准W3C盒子模型和IE盒子模型CSS布局经典盒子模型(转)
查看>>
SQL Server 2008高可用×××介绍
查看>>
STP收敛
查看>>
VirtualBox无法进入Win8PE的桌面
查看>>
Cisco3550 交换机 端口限速
查看>>
Linux卸载系统自带的httpd的方法
查看>>
《Oracle从入门到精通》读书笔记第十五章 Oracle数据备份与恢复之二
查看>>
Android安全讲座第九层(二) 内存dump
查看>>
弹出菜单效果
查看>>
SQL常用语句集合(不断更新)
查看>>
centos 5 安装教程注意事项
查看>>
回顾2014,展望2015
查看>>
BIOS基础知识(下)
查看>>
nmom结果记录
查看>>
Iterator 和 Iterable 区别和联系
查看>>
经典SQL语句大全
查看>>
测试LCD1602的显示,显示时间,提示语
查看>>
Linux常用命令
查看>>
SecureCRT 连接Ubuntu乱码解决
查看>>