zoukankan      html  css  js  c++  java
  • 第一次加载应用时的滑动启动页

    首先新建一个类: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];
        }
    }
  • 相关阅读:
    Asp.Net : 实现一个 DataSet 或DataTable SELECT DISTINCT (字段唯一性)
    Jquery 局部刷新及 表单取值赋值 处理返回json数据 一些基本操作
    C# 自动化模型编辑Word
    泛型集合List的添加、访问、遍历和删除
    泛型转DataTable方法
    服务器按钮如何通过js验证再触发提交事件?
    Asp.Net 无限分类生成表格 &lt;后台自定义输出table&gt;
    table的innerHTML “未知运行错误”。
    js 截取字符串的方法 C# 正则判断数字及截取字符
    Microsoft Office Visio 2007 设计数据库关系图
  • 原文地址:https://www.cnblogs.com/h-tao/p/5038826.html
Copyright © 2011-2022 走看看