第一次加载应用时的滑动启动页

首先新建一个类:SplashViewController

还是直接贴代码: .h文件

#import <UIKit/UIKit.h>
#import "UIButton+Bootstrap.h"

@interface SplashViewController : UIViewController{

}
//页数量
@property (nonatomic,assign)  NSInteger pagecount;
//是否动画
@property (nonatomic, assign) BOOL isanimating;
//滑动页视图
@property (nonatomic, strong) UIScrollView  *pageScroll;
//是否显示按钮
@property (nonatomic,retain)  UIButton* enter_button;

//添加切换页
-(void)addpage:(NSString*)imagename;

//添加进入按钮
-(void)addenterbutton:(NSString*)title imgNor:(NSString*)imgnor imgPress:(NSString*)imgpress;

//显示
- (void)show;

//隐藏
- (void)hide;

//单例
+(SplashViewController*) sharedSplashViewController;

//获取屏幕大小
-(CGRect) getscreenFrame;

@end

.m文件:

#import "SplashViewController.h"
//#import "RailwayClientApplication.h"

@interface SplashViewController ()

@end

@implementation SplashViewController

@synthesize isanimating = _isanimating;
@synthesize pageScroll  = _pageScroll;
@synthesize enter_button;
@synthesize pagecount;

static SplashViewController *instance = nil;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self){
        self.view.frame = CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height);
        self.view.backgroundColor = [UIColor whiteColor];
        self.pagecount=0;

        //[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }
    return self;
}

//添加切换页
-(void)addpage:(NSString*)imagename{

    UIImageView      *view;
    view = [[UIImageView alloc] initWithFrame:CGRectMake((self.view.frame.size.width * pagecount), 0, self.view.frame.size.width, Main_Screen_Height)];
    UIImage *img=[UIImage imageNamed:imagename];
    view.image = img;
    view.userInteractionEnabled = YES;
//    UIEdgeInsets insets = UIEdgeInsetsMake(10, 10, 400, 10);
//    img=[img resizableImageWithCapInsets:insets];
//    view.backgroundColor = [UIColor colorWithPatternImage:img];

//    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//    view.contentMode = UIViewContentModeScaleAspectFill;
//    

    [self.pageScroll addSubview:view];
    pagecount++;
    self.pageScroll.contentSize = CGSizeMake(self.view.frame.size.width * pagecount, Main_Screen_Height);
}

//添加进入按钮
-(void)addenterbutton:(NSString*)title imgNor:(NSString*)imgnor imgPress:(NSString*)imgpress{
    enter_button= [UIButton buttonWithType:UIButtonTypeSystem];
    self.enter_button.frame=CGRectMake(0.f, 0.f, 175.f, 35.f);
    [self.enter_button setTitle:title forState:UIControlStateNormal];
    [self.enter_button orangerStyle];
//    [enter_button setTitle:title forState:UIControlStateNormal];
//    [enter_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [enter_button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self.enter_button setCenter:CGPointMake(self.view.center.x, Main_Screen_Height - 70)];
//    [enter_button setBackgroundImage:[UIImage imageNamed:imgnor] forState:UIControlStateNormal];
//    [enter_button setBackgroundImage:[UIImage imageNamed:imgpress] forState:UIControlStateHighlighted];
    [self.enter_button addTarget:self action:@selector(pressEnterButton:) forControlEvents:UIControlEventTouchUpInside];

    UIView *uiview=[self.pageScroll.subviews objectAtIndex:self.pageScroll.subviews.count-1];
    if(self.enter_button!=nil){
        [self.enter_button addTarget:self action:@selector(pressEnterButton:) forControlEvents:UIControlEventTouchUpInside];
        [uiview addSubview:self.enter_button];
    }
}

//加载视图
- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect frame=[UIScreen mainScreen].bounds;

    if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) {
//        [self.navigationBar setBarTintColor:[UIColor redColor]];
        [self.navigationController.navigationBar setTranslucent:NO];
    }
    _pageScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    self.pageScroll.pagingEnabled = YES;
    [self.view addSubview:self.pageScroll];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

//单例
+(SplashViewController*) sharedSplashViewController{
    @synchronized(self){
        if(instance==nil){
            instance=[[SplashViewController alloc]init];
        }
    }
    return instance;
}

//显示
- (void)show{
    [self.pageScroll setContentOffset:CGPointMake(0.f, 0.f)];
    [self showPage];
}

//隐藏
- (void)hide{
    [self hidePage];
}

//获取屏幕大小
-(CGRect) getscreenFrame{
    return  CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height);//[UIScreen mainScreen].applicationFrame;
}

//偏移屏幕
- (CGRect)offscreenFrame
{
    CGRect frame = [self getscreenFrame];
    switch ((NSInteger)[UIApplication sharedApplication].statusBarOrientation)
    {
        case UIInterfaceOrientationPortrait:
            frame.origin.y = frame.size.height;
            break;
        case UIInterfaceOrientationPortraitUpsideDown:
            frame.origin.y = -frame.size.height;
            break;
        case UIInterfaceOrientationLandscapeLeft:
            frame.origin.x = frame.size.width;
            break;
        case UIInterfaceOrientationLandscapeRight:
            frame.origin.x = -frame.size.width;
            break;
    }
    return frame;
}

//停止动画
- (void)stopAnimation
{
    _isanimating = NO;
}

//进入事件
- (void)pressEnterButton:(UIButton *)enterButton
{
    [self hidePage];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isnofirst"];

//    [[NSUserDefaults standardUserDefaults] setInteger:2 forKey:@"skin_type"];
//    [[NSUserDefaults standardUserDefaults] setValue:G_APPVERSION forKey:@"platform_type"];
//    [[NSUserDefaults standardUserDefaults] synchronize];
//    [RailwayClientApplication getInstance].appsetings.platform_type=G_APPVERSION;
////    [RailwayClientApplication getInstance].appsetings.skin_type=2;
//
//    [self dismissModalViewControllerAnimated:YES];

//    [RailwayClientApplication showLoginViewController];
}

//从视图中移除
- (void)subviewHidden
{
    _isanimating = NO;
    [[[SplashViewController sharedSplashViewController] view] removeFromSuperview];
}

//显示页面
- (void)showPage
{
    if (!_isanimating && self.view.superview == nil)
    {
        [SplashViewController sharedSplashViewController].view.frame = [self offscreenFrame];
        //[[RailwayClientApplication getMainWindow] addSubview:[SplashViewController sharedSplashViewController].view];
        [[self getMainWindow] addSubview:[SplashViewController sharedSplashViewController].view];
        _isanimating = YES;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(stopAnimation)];
        [SplashViewController sharedSplashViewController].view.frame = [self getscreenFrame];
        [UIView commitAnimations];
    }
}
//获取主窗口
- (UIWindow *)getMainWindow
{
    UIApplication *app = [UIApplication sharedApplication];
    if ([app.delegate respondsToSelector:@selector(window)])
    {
        return [app.delegate window];
    }
    else
    {
        return [app keyWindow];
    }
}

//隐藏
- (void)hidePage
{
    if (!_isanimating && self.view.superview != nil)
    {
        _isanimating = YES;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(subviewHidden)];
        [SplashViewController sharedSplashViewController].view.frame = [self offscreenFrame];
        [UIView commitAnimations];
    }
}

@end

在要引用启动页的类中插入一下代码:

//显示快显视图
-(void)showSplashViewController{
    //第一次启动程序的过场动画
    if ( [[NSUserDefaults standardUserDefaults] boolForKey:@"isnofirst"] == NO) {
        //添加切换页面
        [[SplashViewController sharedSplashViewController]addpage:@"ydy_1.jpg"];
        [[SplashViewController sharedSplashViewController]addpage:@"ydy_2.jpg"];
        [[SplashViewController sharedSplashViewController]addpage:@"ydy_3.jpg"];
        [[SplashViewController sharedSplashViewController]addpage:@"ydy_4.jpg"];
        //添加进入按钮
        [[SplashViewController sharedSplashViewController]addenterbutton:@"开始进入" imgNor:@"btn_nor" imgPress:@"btn_press"];
        [[SplashViewController sharedSplashViewController] show];
    }
}
时间: 2024-08-25 23:13:31

第一次加载应用时的滑动启动页的相关文章

(Spring加载xml时)org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element &#39;beans&#39;.

ApplicationContext ctx = new ClassPathXmlApplicationContext("test.xml");报错 在启动Spring时,报以下错误,如图: 原因是在xml中spring的xsd的版本配置的不一致,我使用的是spring-2.5.6,但配置文件中配的是3.0.改成如下即可: [xhtml] view plain copy <?xml version="1.0" encoding="UTF-8"

用C3中的animation和transform写的一个模仿加载的时动画效果

用用C3中的animation和transform写的一个模仿加载的时动画效果! 不多说直接上代码; html标签部分 <div class="wrap"> <h2>用C3中的animation和transform写的一个模仿加载的时动画效果</h2> <div class="demo"> <div></div> <div></div> <div></d

提高网站第一次加载速度

特别是在手机端访问,用户第一次打开网站,如果得到反馈的时间太久,用户很可能在页面完成加载之前就离开,不会再次访问.所以,网站.web App,提高首次访问的加载速度就显得特别重要了.第一次加载速度是用"首字节的时间"测量的,即从用户点击访问到从服务器返回第一个字节所用的时间,绝大多数情况下,真正的原因在于前端,PageSpeed YSlow和其他无数的工具和服务用来解决这些问题. 浏览器是如何加载页面的 解析域名à发起请求à下载响应à渲染页面 当浏览器要渲染页面的时候,如果页面中有CS

动态链接库DLL的加载:隐式加载(载入时加载)和显式加载(运行时加载)

静态链接库在链接时,编译器会将 .obj 文件和 .LIB 文件组织成一个 .exe 文件,程序运行时,将全部数据加载到内存. 如果程序体积较大,功能较为复杂,那么加载到内存中的时间就会比较长,最直接的一个例子就是双击打开一个软件,要很久才能看到界面.这是静态链接库的一个弊端. 动态链接库有两种加载方式:隐式加载和显示加载. 隐式加载又叫载入时加载,指在主程序载入内存时搜索DLL,并将DLL载入内存.隐式加载也会有静态链接库的问题,如果程序稍大,加载时间就会过长,用户不能接受. 显式加载又叫运行

seajs加载jquery时提示$ is not a function该怎么解决

这篇文章主要介绍了seajs加载jquery时提示$ is not a function该怎么解决的相关资料,需要的朋友可以参考下 jquery1.7以上的都支持模块化加载,只是jquery默认的是支持amd,不支持cmd.所以要用seajs加载jquery时,我们需要稍微做下改动,需要把以下内容做下修改,具体修改方式如下: 把 ? 1 2 3 4 5 if (typeof define === "function" && (define.amd)) {   defin

Struts2配置拦截器,struts2加载常量时的搜索顺序

1:struts2加载常量时的搜索顺序 1.Struts-default.xml 2.Struts-plugin.xml 3.Struts.xml 4.Struts-properties(自己创建的) 5.web.xml 如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面的文件配置的常量值 2:Struts2拦截器配置 1.在Struts.xml中配置一个默认请求的action <!-- 没有找到action时默认执行的action --> <default-acti

高性能网站优化-确保异步加载脚本时保持执行顺序

<高性能网站建设进阶指南> 脚本如果按照常规方式加载,不仅会阻塞页面中其他内容的下载,还会阻塞脚本后面所有元素的渲染.异步加载脚本可以避免这种阻塞现象,从而提高页面加载速度.但是性能的提升是要付出代价的.代码的异步执行可能会出现竞争状态.简单地说就是页面内部的脚本需要的标示符如果是在外部文件中定义的,而当外部文件异步加载的时候,如果没有保证外部文件和内部脚本执行顺序,很有可能会出现未定义标示符的错误 当异步加载的外部脚本与行内脚本之间存在代码依赖时,就需要通过一种保证执行顺序的方法来整合这两个

【转载】Spring加载resource时classpath*:与classpath:的区别

免责声明:     本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除.     原文作者:kyfxbl     原文地址: spring配置中classpath和classpath*的区别   在spring配置文件里,可以用classpath:前缀,来从classpath中加载资源  比如在src下有一个jdbc.properties的文件,可以用如下方法加载: <bean id="propertyConfigurer" class="

如何实现加载DOM时执行js代码

有一些功能需求,需要在DOM载入时马上执行一些函数,但又不愿意仅为了这一个需求而引入整个JQuery库,于是就把jQuery的方法提取出来,单独使用了. 大家可以使用windows.onload事件,但onload在看来,就是页面上的东西(img,iframe等资源)全部都加载完毕后才能发生,如果页面内有大的图片的话,会在页面展现后好久时间后才执行.鸿运国际娱乐城 如果只需要对DOM进行操作,那么这时就没必要等到页面全部加载了.我们需要更快的方法.Firefox有DOMContentLoaded