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
接下来的视频资料找不到了,所以这个项目就到此吧!