Added animation.

This commit is contained in:
makowildcat 2014-04-10 12:45:03 +02:00
parent 0e89f0d743
commit daf07a0459
3 changed files with 43 additions and 8 deletions

View File

@ -35,7 +35,7 @@
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.readerView displayPageAtIndex:0];
[self.readerView displayPageAtIndex:0 animated:NO];
}
- (int) numberOfPages
{

View File

@ -19,6 +19,6 @@
@property (nonatomic, weak) id<ReaderViewDelegate> delegate;
- (void) displayPageAtIndex:(int)index;
- (void) displayPageAtIndex:(int)index animated:(BOOL) animated;
@end

View File

@ -33,12 +33,47 @@
// Drawing code
}
*/
-(void)displayPageAtIndex:(int)index
-(void)displayPageAtIndex:(int)index animated:(BOOL)animated
{
if (index >= 0 && index < [self.delegate numberOfPages]) {
if (!animated) {
[self.subviews.lastObject removeFromSuperview];
UIView * view = [self.delegate pageAtIndex:index];
[self addSubview:view];
}
else {
UIView * oldView = [self.subviews lastObject];
UIView * newView = [self.delegate pageAtIndex:index];
[self addSubview:newView];
CGPoint center = newView.center;
CGPoint left = CGPointMake(center.x - self.bounds.size.width, center.y);
CGPoint right = CGPointMake(center.x + self.bounds.size.width, center.y);
if (index < self.currentIndex) {
// page précédente
newView.center = left;
[UIView animateWithDuration:.3
animations:^{
newView.center = center;
oldView.center = right;
}
completion:^(BOOL finished) {
[oldView removeFromSuperview];
}];
}
else {
// page suivante
newView.center = right;
[UIView animateWithDuration:.3
animations:^{
newView.center = center;
oldView.center = left;
}
completion:^(BOOL finished) {
[oldView removeFromSuperview];
}];
}
}
self.currentIndex = index;
}
}
@ -61,10 +96,10 @@
- (void) previousPage
{
[self displayPageAtIndex:self.currentIndex-1];
[self displayPageAtIndex:self.currentIndex-1 animated:YES];
}
- (void) nextPage
{
[self displayPageAtIndex:self.currentIndex+1];
[self displayPageAtIndex:self.currentIndex+1 animated:YES];
}
@end