//用下边两个函数来记录touch的起始和终止位置
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
startPosition = [touch locationInView:self.view];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
endPosition = [touch locationInView:self.view];
[self handleFlip];
}
//调用系统本身的动画显示效果 [UIView beginAnimations:@"animationID" context:nil]; [UIView setAnimationDuration:0.7f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationRepeatAutoreverses:NO]; UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; [currentView removeFromSuperview]; [self.view addSubview:contentView]; [UIView commitAnimations]; //动画显示只有2中,一种是 UIViewAnimationTransitionCurlDown;一种是 UIViewAnimationTransitionCurlUp.
只要x2<x1,则是向前翻页,否则向后翻页;在翻页时,确定翻到哪个页面是通过UIView的tag来记录的,手工将当前的数据源的index赋值于tag即可。