我是這樣做的:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.startX = scrollView.contentOffset.x;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
//NSLog(@"scrollViewDidEndDragging");
self.endX = scrollView.contentOffset.x;
self.photoIdx = (int)self.startX/Normalize(1160);
if (decelerate == FALSE)
{
int intoThePhoto = (int)self.photoScrollView.contentOffset.x % Normalize(1160);
if (intoThePhoto < Normalize(1060/2))
[scrollView setContentOffset:CGPointMake(Normalize(1160)*self.photoIdx,0) animated:YES];
else
[scrollView setContentOffset:CGPointMake(Normalize(1160)*(self.photoIdx+1),0) animated:YES];
}
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
if ((self.endX - self.startX) > 0 && self.photoIdx < ([self.photos count] -1))
[scrollView setContentOffset:CGPointMake(Normalize(1160)*(self.photoIdx+1),0) animated:YES];
else if ((self.endX - self.startX) < 0 && self.photoIdx != 0)
[scrollView setContentOffset:CGPointMake(Normalize(1160)*(self.photoIdx-1),0) animated:YES];
}
想你!這真的拯救了我的一天。 – dhrm