我正在尝试根据 UIScrollView 的滚动使轮子平滑旋转。当它几乎停止滚动滚动视图时,我希望它能够缓解。
我尝试了很多但到目前为止失败了,我当前的代码是这样的:
#pragma mark - Scrollview delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
NSLog(@"Offset: %@ Page: %i", NSStringFromCGPoint(scrollView.contentOffset), page);
UIImageView* leftWheelImageView = (UIImageView*)[self.carImageView viewWithTag:10];
// Calculate speed of scrolling and turn the wheels to it
CGPoint currentOffset = scrollView.contentOffset;
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
if(lastTime - currentTime > 0.1) {
CGFloat distance = currentOffset.x - lastOffset.x;
CGFloat scrollSpeedNotAbs = (distance * 10) / 1000; //in pixels per millisecond
CGFloat scrollSpeed = fabsf(scrollSpeedNotAbs);
leftWheelImageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(2*3.14*99));
NSLog(@"Rotate wheel");
}
lastOffset = currentOffset;
lastTime = currentTime;
}
谁能把我推向正确的方向:-)?