|
|
@@ -8,6 +8,8 @@
|
|
|
|
|
|
#import "CycleScrollView.h"
|
|
|
#import "NSTimer+Addition.h"
|
|
|
+#import "SliderPage.h"
|
|
|
+#import "HWWeakTimer.h"
|
|
|
|
|
|
@interface CycleScrollView () <UIScrollViewDelegate>
|
|
|
|
|
|
@@ -16,28 +18,54 @@
|
|
|
@property (nonatomic , strong) NSMutableArray *contentViews;
|
|
|
@property (nonatomic , strong) UIScrollView *scrollView;
|
|
|
|
|
|
-@property (nonatomic , strong) NSTimer *animationTimer;
|
|
|
+@property (nonatomic , weak) NSTimer *animationTimer;
|
|
|
@property (nonatomic , assign) NSTimeInterval animationDuration;
|
|
|
@property (nonatomic , strong) UIPageControl *pageControl;
|
|
|
@end
|
|
|
|
|
|
@implementation CycleScrollView
|
|
|
-
|
|
|
+-(void) dealloc
|
|
|
+{
|
|
|
+ [self.animationTimer invalidate];
|
|
|
+ NSLog(@"CycleScrollView dealloc");
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+-(void) stopTimmer
|
|
|
+{
|
|
|
+// return;
|
|
|
+ [self.animationTimer invalidate];
|
|
|
+
|
|
|
+// [[NSNotificationCenter defaultCenter] removeObserver:self name:CYCLESCROLL_STOPTIMMER object:nil];
|
|
|
+}
|
|
|
-(void) animationDuration:(NSTimeInterval)animationDuration
|
|
|
{
|
|
|
+ // return;
|
|
|
+
|
|
|
if (animationDuration > 0.0) {
|
|
|
- self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
|
|
|
- target:self
|
|
|
- selector:@selector(animationTimerDidFired:)
|
|
|
- userInfo:nil
|
|
|
- repeats:YES];
|
|
|
+// self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
|
|
|
+// target:self
|
|
|
+// selector:@selector(animationTimerDidFired:)
|
|
|
+// userInfo:nil
|
|
|
+// repeats:YES];
|
|
|
+
|
|
|
+ self.animationTimer = [HWWeakTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
|
|
|
+ target:self
|
|
|
+ selector:@selector(animationTimerDidFired:)
|
|
|
+ userInfo:nil
|
|
|
+ repeats:YES];
|
|
|
+
|
|
|
+// self.animationTimer =[HWWeakTimer scheduledTimerWithTimeInterval:3.0f block:^(id userInfo) {
|
|
|
+// NSLog(@"%@", userInfo);
|
|
|
+// } userInfo:@"Fire" repeats:YES];
|
|
|
[self.animationTimer pauseTimer];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (void)setTotalPagesCount:(NSInteger (^)(void))totalPagesCount
|
|
|
+- (void)setTotalPagesCount
|
|
|
{
|
|
|
- _totalPageCount = totalPagesCount();
|
|
|
+
|
|
|
+ _totalPageCount = self.arr_Pages.count;
|
|
|
if (_totalPageCount > 0) {
|
|
|
[self configContentViews];
|
|
|
[self.animationTimer resumeTimerAfterTimeInterval:self.animationDuration];
|
|
|
@@ -54,7 +82,7 @@
|
|
|
self.arr_Pages =[@[] mutableCopy];
|
|
|
// Initialization code
|
|
|
self.autoresizesSubviews = YES;
|
|
|
- self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
|
|
|
+// self.scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
|
|
|
self.scrollView.autoresizingMask = 0xFF;
|
|
|
self.scrollView.contentMode = UIViewContentModeCenter;
|
|
|
self.scrollView.contentSize = CGSizeMake(3 * CGRectGetWidth(self.scrollView.frame), CGRectGetHeight(self.scrollView.frame));
|
|
|
@@ -64,15 +92,15 @@
|
|
|
self.scrollView.delegate = self;
|
|
|
self.scrollView.contentOffset = CGPointMake(CGRectGetWidth(self.scrollView.frame), 0);
|
|
|
self.scrollView.pagingEnabled = YES;
|
|
|
- [self addSubview:self.scrollView];
|
|
|
+// [self addSubview:self.scrollView];
|
|
|
|
|
|
- CGRect pageFrame =self.bounds;
|
|
|
- pageFrame.origin.y = self.frame.size.height -16-20;
|
|
|
- pageFrame.size.height = 20;
|
|
|
+// CGRect pageFrame =self.bounds;
|
|
|
+// pageFrame.origin.y = self.frame.size.height -16-20;
|
|
|
+// pageFrame.size.height = 20;
|
|
|
// pageFrame
|
|
|
- self.pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];//CGRectMake(0, self.frame.size.height -16-10, 320, 10)];
|
|
|
+// self.pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];//CGRectMake(0, self.frame.size.height -16-10, 320, 10)];
|
|
|
self.pageControl.userInteractionEnabled = NO;
|
|
|
- [self addSubview:self.pageControl];
|
|
|
+// [self addSubview:self.pageControl];
|
|
|
// int count =self.totalPageCount;
|
|
|
// self.pageControl.backgroundColor = [UIColor purpleColor];
|
|
|
self.pageControl.numberOfPages = self.totalPageCount;
|
|
|
@@ -91,14 +119,16 @@
|
|
|
- (id)initWithFrame:(CGRect)frame animationDuration:(NSTimeInterval)animationDuration
|
|
|
{
|
|
|
self = [self initWithFrame:frame];
|
|
|
- if (animationDuration > 0.0) {
|
|
|
- self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
|
|
|
- target:self
|
|
|
- selector:@selector(animationTimerDidFired:)
|
|
|
- userInfo:nil
|
|
|
- repeats:YES];
|
|
|
- [self.animationTimer pauseTimer];
|
|
|
- }
|
|
|
+// if (animationDuration > 0.0) {
|
|
|
+// self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(self.animationDuration = animationDuration)
|
|
|
+// target:self
|
|
|
+// selector:@selector(animationTimerDidFired:)
|
|
|
+// userInfo:nil
|
|
|
+// repeats:YES];
|
|
|
+// [self.animationTimer pauseTimer];
|
|
|
+// }
|
|
|
+
|
|
|
+ [self animationDuration:animationDuration];
|
|
|
return self;
|
|
|
}
|
|
|
|
|
|
@@ -117,6 +147,16 @@
|
|
|
self.scrollView.pagingEnabled = YES;
|
|
|
[self addSubview:self.scrollView];
|
|
|
self.currentPageIndex = 0;
|
|
|
+
|
|
|
+
|
|
|
+ CGRect pageFrame =self.bounds;
|
|
|
+ pageFrame.origin.y = self.frame.size.height -16-20;
|
|
|
+ pageFrame.size.height = 20;
|
|
|
+ self.pageControl = [[UIPageControl alloc] initWithFrame:pageFrame];
|
|
|
+ [self addSubview:self.pageControl];
|
|
|
+
|
|
|
+
|
|
|
+// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopTimmer) name:CYCLESCROLL_STOPTIMMER object:nil];
|
|
|
}
|
|
|
return self;
|
|
|
}
|
|
|
@@ -154,17 +194,36 @@
|
|
|
}
|
|
|
[self.contentViews removeAllObjects];
|
|
|
|
|
|
- if (self.fetchContentViewAtIndex) {
|
|
|
- [self.contentViews addObject:self.fetchContentViewAtIndex(previousPageIndex)];
|
|
|
- [self.contentViews addObject:self.fetchContentViewAtIndex(_currentPageIndex)];
|
|
|
+// if (self.fetchContentViewAtIndex)
|
|
|
+ {
|
|
|
|
|
|
|
|
|
- UIView* currentView =self.fetchContentViewAtIndex(_currentPageIndex);
|
|
|
- currentView.gestureRecognizers= nil;
|
|
|
+
|
|
|
+ SliderPage* previousPage =self.arr_Pages[previousPageIndex];
|
|
|
+ [previousPage loadImage];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ [self.contentViews addObject:previousPage];
|
|
|
+
|
|
|
+
|
|
|
+ SliderPage* currentPage =self.arr_Pages[_currentPageIndex];
|
|
|
+ [currentPage loadImage];
|
|
|
+ [self.contentViews addObject:currentPage];
|
|
|
+
|
|
|
+
|
|
|
+// UIView* currentView =self.fetchContentViewAtIndex(_currentPageIndex);
|
|
|
+ currentPage.gestureRecognizers= nil;
|
|
|
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentViewTapAction:)];
|
|
|
- [self.fetchContentViewAtIndex(_currentPageIndex) addGestureRecognizer:tapGesture];
|
|
|
+ [currentPage addGestureRecognizer:tapGesture];
|
|
|
+
|
|
|
+
|
|
|
+ SliderPage* rearPage =self.arr_Pages[rearPageIndex];
|
|
|
+ [rearPage loadImage];
|
|
|
|
|
|
- [self.contentViews addObject:self.fetchContentViewAtIndex(rearPageIndex)];
|
|
|
+ [self.contentViews addObject:rearPage];
|
|
|
}
|
|
|
}
|
|
|
|