Image navigation.
This commit is contained in:
parent
da83305a1d
commit
a47da4d9f0
@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
#import "ReaderView.h"
|
#import "ReaderView.h"
|
||||||
|
|
||||||
|
@interface ReaderView ()
|
||||||
|
|
||||||
|
@property (nonatomic, assign) int currentIndex;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation ReaderView
|
@implementation ReaderView
|
||||||
|
|
||||||
- (id)initWithFrame:(CGRect)frame
|
- (id)initWithFrame:(CGRect)frame
|
||||||
@ -20,16 +26,44 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Only override drawRect: if you perform custom drawing.
|
// Only override drawRect: if you perform custom drawing.
|
||||||
// An empty implementation adversely affects performance during animation.
|
// An empty implementation adversely affects performance during animation.
|
||||||
- (void)drawRect:(CGRect)rect
|
- (void)drawRect:(CGRect)rect
|
||||||
{
|
{
|
||||||
// Drawing code
|
// Drawing code
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
-(void)displayPageAtIndex:(int)index
|
-(void)displayPageAtIndex:(int)index
|
||||||
{
|
{
|
||||||
UIView * view = [self.delegate pageAtIndex:index];
|
if (index >= 0 && index < [self.delegate numberOfPages]) {
|
||||||
[self addSubview:view];
|
UIView * view = [self.delegate pageAtIndex:index];
|
||||||
|
[self addSubview:view];
|
||||||
|
self.currentIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
- (void)layoutSubviews
|
||||||
|
{
|
||||||
|
if (!self.gestureRecognizers.count) {
|
||||||
|
UISwipeGestureRecognizer * previousPageRecognizer =
|
||||||
|
[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousPage)];
|
||||||
|
previousPageRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
|
||||||
|
[self addGestureRecognizer:previousPageRecognizer];
|
||||||
|
|
||||||
|
UISwipeGestureRecognizer * nextPageRecognizer =
|
||||||
|
[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextPage)];
|
||||||
|
nextPageRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
|
||||||
|
[self addGestureRecognizer:nextPageRecognizer];
|
||||||
|
|
||||||
|
self.userInteractionEnabled = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) previousPage
|
||||||
|
{
|
||||||
|
[self displayPageAtIndex:self.currentIndex-1];
|
||||||
|
}
|
||||||
|
- (void) nextPage
|
||||||
|
{
|
||||||
|
[self displayPageAtIndex:self.currentIndex+1];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user