轮播图
//
// ViewController.m
//轮播图
//
// Created by lanou on 16/7/13.
// Copyright©2016年lanou. All rights reserved.
//
#import"ViewController.h"
//
@interfaceViewController()
//宏定义
#define screenWidth [UIScreen mainScreen].bounds.size.width
#define screenHeight [UIScreen mainScreen].bounds.size.height
//滑动视图UIScrollView,自带了可滑动功能
@property(nonatomic,strong)UIScrollView*scrollView;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
//屏幕宽高
//创建初始化滑动视图
self.scrollView= [[UIScrollViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
for(NSIntegeri =0; i <6; i++) {
//根据i循环创建UIImageView,再添加到滑动视图UIScrollView上面
UIImageView*imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(i*screenWidth,0,screenWidth,screenHeight)];
NSString*imagename =nil;
if(i==5) {
imagename =@"1.jpg";
}else{
imagename = [NSStringstringWithFormat:@"%ld.jpg",i+1];
}
//加载响应的图片
UIImage*image = [UIImageimageNamed:imagename];
//设置图片
imageView.image= image ;
//将imageview添加到滑动视图上面
[self.scrollViewaddSubview:imageView];
//设置滑动视图的滑动区域contentSize
self.scrollView.contentSize=CGSizeMake(6*screenWidth,screenHeight);
//整屏翻转
self.scrollView.pagingEnabled=YES;
//边界回弹
self.scrollView.bounces=NO;
//设置代理,代理是负责监听滑动是要整个过程的
self.scrollView.delegate=self;
}
//添加到滑动视图屏幕上面
[self.viewaddSubview:self.scrollView];
}
//滑动视图做滑动的时候调用
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
//contentoffset是访问到了滑动视图的偏移量,包含了x,和y轴的偏移量
//setContentOffset:animated:
NSLog(@"offset.x = %f,offset.y = %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
rk": f�y=�q�