Added animation.
This commit is contained in:
parent
0e89f0d743
commit
daf07a0459
@ -35,7 +35,7 @@
|
|||||||
- (void) viewDidAppear:(BOOL)animated
|
- (void) viewDidAppear:(BOOL)animated
|
||||||
{
|
{
|
||||||
[super viewDidAppear:animated];
|
[super viewDidAppear:animated];
|
||||||
[self.readerView displayPageAtIndex:0];
|
[self.readerView displayPageAtIndex:0 animated:NO];
|
||||||
}
|
}
|
||||||
- (int) numberOfPages
|
- (int) numberOfPages
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,6 @@
|
|||||||
|
|
||||||
@property (nonatomic, weak) id<ReaderViewDelegate> delegate;
|
@property (nonatomic, weak) id<ReaderViewDelegate> delegate;
|
||||||
|
|
||||||
- (void) displayPageAtIndex:(int)index;
|
- (void) displayPageAtIndex:(int)index animated:(BOOL) animated;
|
||||||
|
|
||||||
@end
|
@end
|
@ -33,12 +33,47 @@
|
|||||||
// Drawing code
|
// Drawing code
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
-(void)displayPageAtIndex:(int)index
|
-(void)displayPageAtIndex:(int)index animated:(BOOL)animated
|
||||||
{
|
{
|
||||||
if (index >= 0 && index < [self.delegate numberOfPages]) {
|
if (index >= 0 && index < [self.delegate numberOfPages]) {
|
||||||
[self.subviews.lastObject removeFromSuperview];
|
if (!animated) {
|
||||||
UIView * view = [self.delegate pageAtIndex:index];
|
[self.subviews.lastObject removeFromSuperview];
|
||||||
[self addSubview:view];
|
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;
|
self.currentIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,10 +96,10 @@
|
|||||||
|
|
||||||
- (void) previousPage
|
- (void) previousPage
|
||||||
{
|
{
|
||||||
[self displayPageAtIndex:self.currentIndex-1];
|
[self displayPageAtIndex:self.currentIndex-1 animated:YES];
|
||||||
}
|
}
|
||||||
- (void) nextPage
|
- (void) nextPage
|
||||||
{
|
{
|
||||||
[self displayPageAtIndex:self.currentIndex+1];
|
[self displayPageAtIndex:self.currentIndex+1 animated:YES];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user