iOS项目实践之时光电影(二)

homeviewcontroller.h

@interface HomeViewController : UIViewController <UIScrollViewDelegate>
{
    @private
    UIScrollView *_scrollView;
    UIPageControl *_pageControl;
}
@end

homeviewcontroller.m

//
//  HomeViewController.m
//  SGMovie
//
//  Created by robin on 16/2/27.
//  Copyright © 2016年 robin. All rights reserved.
//

#import "HomeViewController.h"

@interface HomeViewController ()

- (void) _initImageView;
@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self _initImageView];
}

- (void) _initImageView
{
    // 初始化滚动视图
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(WXHLApplicationBounds().origin.x,WXHLApplicationBounds().origin.y, IPHONE_WIDTH, WXHLApplicationFrame().size.height- TABBAR_HEIGHT)];
    
    _scrollView.contentSize = CGSizeMake(IPHONE_WIDTH*4,  WXHLApplicationFrame().size.height- TABBAR_HEIGHT - WXHLkDefaultPortraitToolbarHeight);
    
    //隐藏滚动条
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.backgroundColor = [UIColor blackColor];
    
    //无反弹效果
    _scrollView.bounces = NO;
    
    //开启分页模式
    _scrollView.pagingEnabled = YES;
    
    //设置代理
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    
    
    //创建分页控件
    _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, WXHLApplicationFrame().size.height-WXHLkDefaultPortraitToolbarHeight-TABBAR_HEIGHT-STATEBAR_HEIGHT, IPHONE_WIDTH, STATEBAR_HEIGHT)];
    _pageControl.numberOfPages = 4;
    _pageControl.currentPage = 0;
    _pageControl.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_pageControl];
    
    
    //创建第一个图片视图
    UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: HOME_SCROL_VIEW_IMAGE_1]];
    image1.contentMode = UIViewContentModeScaleAspectFit;
    image1.userInteractionEnabled = YES;
    image1.backgroundColor = [UIColor blackColor];
    image1.frame = CGRectMake(0, 0, IPHONE_WIDTH, WXHLApplicationFrame().size.height - WXHLkDefaultPortraitToolbarHeight-TABBAR_HEIGHT);
    [_scrollView addSubview:image1];
    
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, WXHLkDefaultPortraitToolbarHeight)];
    searchBar.delegate = self;
    searchBar.tag = 100;
    searchBar.placeholder = @"搜索影人/电影";
    [image1 addSubview:searchBar];
    
    [searchBar setBackgroundImage:[UIImage imageNamed:@"top_bg.png"]];
    
    
    UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: HOME_SCROL_VIEW_IMAGE_2]];
    image2.contentMode = UIViewContentModeScaleAspectFit;
    image2.userInteractionEnabled = YES;
    image2.backgroundColor = [UIColor blackColor];
    image2.frame = CGRectMake(IPHONE_WIDTH*1, 0, IPHONE_WIDTH, WXHLApplicationFrame().size.height - WXHLkDefaultPortraitToolbarHeight-TABBAR_HEIGHT);
    [_scrollView addSubview:image2];
    
    
    UIImageView *image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: HOME_SCROL_VIEW_IMAGE_3]];
    image3.contentMode = UIViewContentModeScaleAspectFit;
    image3.userInteractionEnabled = YES;
    image3.backgroundColor = [UIColor blackColor];
    image3.frame = CGRectMake(IPHONE_WIDTH*2, 0, IPHONE_WIDTH, WXHLApplicationFrame().size.height - WXHLkDefaultPortraitToolbarHeight-TABBAR_HEIGHT);
    [_scrollView addSubview:image3];
    
    UIImageView *image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed: HOME_SCROL_VIEW_IMAGE_4]];
    image4.contentMode = UIViewContentModeScaleAspectFit;
    image4.userInteractionEnabled = YES;
    image4.backgroundColor = [UIColor blackColor];
    image4.frame = CGRectMake(IPHONE_WIDTH*3, 0, IPHONE_WIDTH, WXHLApplicationFrame().size.height - WXHLkDefaultPortraitToolbarHeight-TABBAR_HEIGHT);
    [_scrollView addSubview:image4];
    
    
}

- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    float index = scrollView.contentOffset.x;
    int pageIndex = index /  IPHONE_WIDTH;
    _pageControl.currentPage = pageIndex;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


然后大致效果如下




接下来的视频资料找不到了,所以这个项目就到此吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值