iOSUI简单的页面轮转
来源:互联网 发布:淘宝男装牛仔衣服 编辑:程序博客网 时间:2024/06/15 14:20
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#import "ViewController.h"
#import "MyScrollView.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
NSArray *array =@[@"sc4.jpg",@"sc0.jpg",@"sc1.jpg",@"sc2.jpg",@"sc3.jpg",@"sc4.jpg",@"sc0.jpg"];
MyScrollView *myScrol = [[MyScrollViewalloc]initWithFrame:CGRectMake(0,0, WIDTH,HEIGHT) andContentSize:CGSizeMake(WIDTH*7,HEIGHT) andHorizontal:NOandVertical:NOandBounces:NOandpagingEnabled:YESandWidth:WIDTHandHeight:HEIGHTandImageArray:array];
[self.viewaddSubview:myScrol];
[myScrol setPage:CGRectMake(40,HEIGHT-60,WIDTH-80,30) andNumberOfPage:5andCurrentPage:0andCurrentColor:[UIColoryellowColor]andPageColor:[UIColorredColor]];
[self.viewaddSubview:myScrol.page];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
#import <UIKit/UIKit.h>
@interface MyScrollView :UIScrollView<UIScrollViewDelegate>
{
NSTimer *_timer;
}
@property(nonatomic ,copy)NSArray *imageArray;//轮转图片名的数组
@property(nonatomic,strong)UIPageControl *page;//图片上的圆点
@property(nonatomic,assign)CGFloat width;//页面的宽
@property(nonatomic,assign)CGFloat height;//页面的高
-(id)initWithFrame:(CGRect)frame andContentSize:(CGSize)size andHorizontal:(BOOL)h andVertical:(BOOL)v andBounces:(BOOL)b andpagingEnabled:(BOOL)p andWidth:(CGFloat)width andHeight:(CGFloat)height andImageArray:(NSArray *)array;//初始化ScrollView
-(void)setPage:(CGRect)frame andNumberOfPage:(NSInteger) num andCurrentPage:(NSInteger)current andCurrentColor:(UIColor*)ccolor andPageColor:(UIColor *)pcolor;//初始化page
@end
#import "MyScrollView.h"
@implementation MyScrollView
-(id)initWithFrame:(CGRect)frame andContentSize:(CGSize)size andHorizontal:(BOOL)h andVertical:(BOOL)v andBounces:(BOOL)b andpagingEnabled:(BOOL)p andWidth:(CGFloat)width andHeight:(CGFloat)height andImageArray:(NSArray *)array{
if (self = [superinitWithFrame:frame]) {//设置画布大小
//当width和height同时小于画布大小的时候 ,控件无法滑动,有其中一个大于画布 则决定滑动的方向同时大于则左右上下都可滑动
//设置画布中内容的大小
self.contentSize = size;
//横向滑动的条去掉
self.showsHorizontalScrollIndicator = h;
//上下的滑动的条去掉
self.showsVerticalScrollIndicator = v;
//反弹
self.bounces = b;
//翻页效果
self.pagingEnabled = p;
self.delegate =self;
_width = width;
_height = height;
_imageArray = array;
//设置timer
_timer = [NSTimerscheduledTimerWithTimeInterval:3target:selfselector:@selector(changeoffSet)userInfo:nilrepeats:YES];
[self addImage];
}
return self;
}
-(void)addImage{
//将图片加入scrollView里面
for (int i=0; i<7; i++) {
UIImageView *imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(_width*i,0, _width, _height)];
imageView.image = [UIImageimageNamed:_imageArray[i]];
[self addSubview:imageView];
}
}
//设置pageControl
-(void)setPage:(CGRect)frame andNumberOfPage:(NSInteger)num andCurrentPage:(NSInteger)current andCurrentColor:(UIColor *)ccolor andPageColor:(UIColor *)pcolor{
_page =[[UIPageControlalloc]initWithFrame:frame];
_page.numberOfPages = num;
_page.currentPage = current;
_page.currentPageIndicatorTintColor = ccolor;
_page.pageIndicatorTintColor = pcolor;
}
//timer要执行的方法 //自动翻转
-(void)changeoffSet{
[UIViewanimateWithDuration:1animations:^{
self.contentOffset =CGPointMake(self.contentOffset.x+_width,0);//contentOffSet偏移量
}completion:^(BOOL finished) {
if (self.contentOffset.x ==6*_width) {
self.contentOffset =CGPointMake(_width,0);
}
_page.currentPage =self.contentOffset.x/_width-1;
}];
}
//代理执行方法 //手动翻转
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//0 1 2 3 4 5 6
//4 0 1 2 3 4 0
if (scrollView.contentOffset.x ==_width*6) {
scrollView.contentOffset = CGPointMake(_width, 0);
NSLog(@"1");
}
else if (scrollView.contentOffset.x ==0) {
scrollView.contentOffset = CGPointMake(_width*5,0);
}
_page.currentPage =self.contentOffset.x/_width-1;
}
@end
- iOSUI简单的页面轮转
- JS实现简单的图片轮转
- 一个简单的时间片轮转内核
- iosUI篇-Date Picker 和 UITool Bar 控件简单的介绍
- 一个简单的时间片轮转多道程序内核代码
- 一个简单的时间片轮转多道程序分析
- 进程调度的优先数法和简单轮转法
- 一个简单的时间片轮转多道程序内核代码
- 简单的时间片轮转多道程序内核代码分析
- 一个简单的时间片轮转多道程序内核代码
- 简单的时间片轮转多道程序内核代码
- 一个简单的时间片轮转多道程序内核代码
- 一个简单的时间片轮转多道程序内核代码
- 完成一个简单的时间片轮转多道程序
- 完成一个简单的时间片轮转多道程序内核
- 简单的时间片轮转多道程序内核代码
- iosUI开发的一些随笔记
- IOSUI瀑布流相册的实现
- Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱
- Programming in Objective-C 学习笔记09——对象复制与归档
- 简单程序循环练习
- SQL 优化
- [BZOJ 2938][Poi2000]病毒
- iOSUI简单的页面轮转
- 架构师的行为准则(一)
- Android的init进程启动过程
- 笔试题:GetMemory()函数
- 获取本机ip
- 使用IntelliJ IDEA开发SpringMVC网站(二)框架配置
- Programming in Objective-C 学习笔记10——Cocoa, Cocoa Touch and the iOS SDK
- Linux调试工具
- Hust oj 1143 泉水(dfs)