iOS scrollerView 滚动 工具类
来源:互联网 发布:淘宝网烟花烫女装 编辑:程序博客网 时间:2024/06/05 09:54
//
// EScrollerView.h
// icoiniPad
//
// Created by Ethan on 12-11-24.
//
//
#import <UIKit/UIKit.h>
@protocol EScrollerViewDelegate <NSObject>
@optional
-(void)EScrollerViewDidClicked:(NSUInteger)index;
@end
@interface EScrollerView :UIView<UIScrollViewDelegate>
@property (nonatomic,assign)id<EScrollerViewDelegate> delegate;
@property (nonatomic,strong) UIScrollView * scrollView;
@property (nonatomic,strong) UIPageControl * pageControl;
@property (nonatomic,assign) NSInteger count;
@property (nonatomic ,strong) NSMutableArray * imageArray;
-(id)initWithFrameRect:(CGRect)rect ImageArray:(NSArray *)imgArr TitleArray:(NSArray *)titArr;
@end
/
// EScrollerView.m
// icoiniPad
//
// Created by Ethan on 12-11-24.
//
//
#import "EScrollerView.h"
@implementation EScrollerView
@synthesize delegate;
-(id)initWithFrameRect:(CGRect)rect ImageArray:(NSArray *)imgArr TitleArray:(NSArray *)titArr
{
if ((self=[superinitWithFrame:rect])) {
self.userInteractionEnabled=YES;
self.scrollView = [[[UIScrollViewalloc] initWithFrame:CGRectMake(0,0, VIEW_WIDTH,self.height)]autorelease];
_scrollView.backgroundColor = [UIColorwhiteColor];
_scrollView.contentSize =CGSizeMake(imgArr.count *VIEW_WIDTH, self.height);
_scrollView.pagingEnabled =YES;
_scrollView.delegate =self;
for (int i =0; i < imgArr.count; i++) {
UIImageView * image = [[UIImageViewalloc] initWithFrame:CGRectMake(VIEW_WIDTH * i,0, self.width,self.height)];
[_scrollViewaddSubview:image];
UITapGestureRecognizer * tapGR = [[[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tap:)]autorelease];
[imagesetImageWithURL:[NSURLURLWithString:[imgArr objectAtIndex:i]]];
//打开界面交互
image.userInteractionEnabled =YES;
//添加手势
[imageaddGestureRecognizer:tapGR];
image.tag =1000 + i;
}
[selfaddSubview:_scrollView];
self.pageControl = [[[UIPageControlalloc] initWithFrame:CGRectMake(110,100, 100, 30)]autorelease];
_pageControl.numberOfPages = imgArr.count;
// _pageControl.backgroundColor = [UIColor cyanColor];
[_pageControladdTarget:selfaction:@selector(changePhoto:)forControlEvents:UIControlEventValueChanged];
[selfaddSubview:_pageControl];
self.imageArray = [NSMutableArrayarrayWithArray:imgArr];
//定时器,循环滚动
_count = 0;
[NSTimerscheduledTimerWithTimeInterval:2target:selfselector:@selector(loopScroll)userInfo:nilrepeats:YES];
}
returnself;
}
- (void)tap:(UITapGestureRecognizer *)tap
{
[self.delegateEScrollerViewDidClicked:tap.view.tag];
}
//滚动视图的循环滚动
- (void)loopScroll
{
//NSLog(@"repeat");
if (self.imageArray.count) {
int a = _count %self.imageArray.count;
_pageControl.currentPage = a;
_count++;
// NSLog(@"%d", _pageControl.currentPage);
//[self change];
//让scrollView随着page改变
[_scrollViewsetContentOffset:CGPointMake(VIEW_WIDTH *_pageControl.currentPage,0) animated:YES];
}
}
//点击pageControl改变滚动视图图片
- (void)changePhoto:(UIPageControl *)pageControl
{
int page = pageControl.currentPage;
NSLog(@"%ld", (long)pageControl.currentPage);
[_scrollViewsetContentOffset:CGPointMake(VIEW_WIDTH * page,0) animated:YES];
_count = page;
}
#pragma mark - UIScrollViewDelegate
//视图结束减速时改变page
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int x = scrollView.contentOffset.x /VIEW_WIDTH;
_pageControl.currentPage = x;
_count = x;
}
@end
- iOS scrollerView 滚动 工具类
- iOS入门之page平铺导航,scrollerview滚动计算和pager的切换
- ios ScrollerView之图片轮播器
- 【iOS】iOS11.0 ScrollerView 适配
- ScrollerView
- scrollerview
- ios打印功能实现(ScrollerView打印)
- IOS UI初级-滑动视图ScrollerView
- ios打印功能实现(ScrollerView打印)
- 使用 ScrollerView 实现 可上下滚动的分类栏
- iOS开发-自定义重用机制给ScrollerView添加子视图
- 【代码笔记】iOS-scrollerView里多个tableView加搜索框
- scrollerView内的数据每次刷新都会滚动到底部处理
- 理解ScrollerView
- scrollerView初探
- ScrollerView 布局
- Scrollerview xib
- iOS工具类
- JS动态变量名 或 字符串与已有变量对应
- svg的js库
- eclipse快捷键
- 排序算法--代码转载自:http://www.slyar.com/blog/c-quicksort.html
- 常用正则表达式
- iOS scrollerView 滚动 工具类
- Java的内存布局
- Java内存管理:深入Java内存区域
- 查看java对象在内存中的布局
- Java内存布局浅谈
- 一个Java对象到底占多大内存?
- Java 日志管理最佳实践
- Java内存区域划分、内存分配原理
- MYSQL索引无效和索引有效的详细介绍