Skip to content

Commit

Permalink
Support to automatically play
Browse files Browse the repository at this point in the history
This commit provide support to set an Autoplay time interval calling to
[self setAutoplayTimeInterval:number_seconds].
  • Loading branch information
menaweb committed Jan 30, 2015
1 parent 18a452e commit 06d1014
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions PagedImageScrollView/PagedImageScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ enum PageControlPosition {
@property (nonatomic, assign) enum PageControlPosition pageControlPos; //default is PageControlPositionRightCorner

- (void)setScrollViewContents: (NSArray *)images;
- (void)setAutoplayTimeInterval:(NSTimeInterval)seconds;
@end
26 changes: 26 additions & 0 deletions PagedImageScrollView/PagedImageScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ @implementation PagedImageScrollView

#define PAGECONTROL_DOT_WIDTH 20
#define PAGECONTROL_HEIGHT 20
#define PAGECONTROL_TIMER_INTERVAL 3.0

- (id)initWithFrame:(CGRect)frame
{
Expand All @@ -33,6 +34,31 @@ - (id)initWithFrame:(CGRect)frame
return self;
}

- (void)setAutoplayTimeInterval:(NSTimeInterval)seconds
{
if (!seconds)
seconds = PAGECONTROL_TIMER_INTERVAL;

NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval: seconds
target: self
selector: @selector(handleTimer)
userInfo: nil
repeats: YES];
}

- (void)handleTimer
{
if (_pageControl.currentPage == _pageControl.numberOfPages-1)
{
_pageControl.currentPage = 0;
}else
{
_pageControl.currentPage = _pageControl.currentPage + 1;
}

[self changePage:self.pageControl];
}

- (void)setPageControlPos:(enum PageControlPosition)pageControlPos
{
Expand Down

1 comment on commit 06d1014

@jianpx
Copy link

@jianpx jianpx commented on 06d1014 Feb 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should invalid timer in dealloc .

Please sign in to comment.