美文网首页
iOS_LoadingController

iOS_LoadingController

作者: 738bc070cd74 | 来源:发表于2015-09-28 13:20 被阅读167次

    App 启动的引导页制作,如下步骤

    • 设置 ViewController 的 View 为 ImageView;
    • 添加 ScrollView 到 ImageView 中;
    • 添加 PageControl 到 ImageView 中;
    • 设置 ScrollView 的代理方法 scrollViewDidEndDecelerating
    #import "LoadingViewController.h"
    
    @interface LoadingViewController ()<UIScrollViewDelegate> {
    
    UIScrollView *_scrollView;
    UIPageControl *_pageControl;
    int _count;
    }
    
    @end
    
    @implementation LoadingViewController
    
    - (void) loadView {
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = [UIScreen mainScreen].bounds;
    imageView.image = [UIImage imageNamed:@"loading_background.png"];
    //imageview 默认不能交互
    imageView.userInteractionEnabled = YES;
    
    self.view = imageView;
    }
    
    - (void)viewDidLoad {
    [super viewDidLoad];
    CGSize viewSize = self.view.frame.size;
    _count = 4;
    _scrollView = [[UIScrollView alloc] init];
    _scrollView.frame = self.view.bounds;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.contentSize = CGSizeMake(_count * self.view.bounds.size.width, 0);
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    
    for (int i = 0; i<_count; i++) {
        [self addImageViewAtIndex:i];
    }
    
    _pageControl = [[UIPageControl alloc] init];
    _pageControl.center = CGPointMake(viewSize.width * 0.5, viewSize.height * 0.9);
    _pageControl.bounds = CGRectMake(0, 0, 100, 0);
    _pageControl.numberOfPages = _count;
    _pageControl.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loading_pagecontrol_point.png"]];
    _pageControl.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"loading_pagecontrol_checked_point.png"]];
    _pageControl.userInteractionEnabled = NO;
    [self.view addSubview:_pageControl];
    }
    
    - (void) addImageViewAtIndex:(int) index
    {
    CGSize viewSize = self.view.frame.size;
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(index * viewSize.width, 0, viewSize.width, viewSize.height);
    NSString *name = [NSString stringWithFormat:@"loading_%d.png", index+1];
    imageView.image = [UIImage imageNamed:name];
    [_scrollView addSubview:imageView];
    
    }
    
    - (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    {
    _pageControl.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
    }
    
    - (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:iOS_LoadingController

          本文链接:https://www.haomeiwen.com/subject/txmwcttx.html