Image navigation.

This commit is contained in:
makowildcat 2014-04-10 12:13:01 +02:00
parent da83305a1d
commit a47da4d9f0

View File

@ -8,6 +8,12 @@
#import "ReaderView.h"
@interface ReaderView ()
@property (nonatomic, assign) int currentIndex;
@end
@implementation ReaderView
- (id)initWithFrame:(CGRect)frame
@ -29,7 +35,35 @@
*/
-(void)displayPageAtIndex:(int)index
{
if (index >= 0 && index < [self.delegate numberOfPages]) {
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