fix(ios): revert scroll animation fix for ios15

This commit is contained in:
luomy
2021-12-13 16:19:58 +08:00
parent 05f8334e72
commit c138dfd377
+1 -37
View File
@@ -347,43 +347,7 @@
return;
}
_targetOffset = contentOffset;
/**
* A protential bug
* It seems that adding subviews onto UIScrollView or changing property
* may cause UIScrollView to stop performing 'setContentOffset' animation in ios 15
* still figure out why
* so we use keyframes animation to simulate 'setContentOffset' animation for now
*/
if (@available(iOS 15, *)) {
if (animated) {
static NSUInteger viewPagerSetContentoffsetFrames = 10;
static CGFloat keyFramesAnimatonDuration = .54f;
CGFloat eachXOffset = (contentOffset.x - self.contentOffset.x) / viewPagerSetContentoffsetFrames;
CGFloat eachYOffset = (contentOffset.y - self.contentOffset.y) / viewPagerSetContentoffsetFrames;
CGPoint currentOffset = self.contentOffset;
[UIView animateKeyframesWithDuration:keyFramesAnimatonDuration delay:0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
CGFloat durationForEachKeyFrameAnimation = keyFramesAnimatonDuration / viewPagerSetContentoffsetFrames;
for (NSUInteger i = 0; i < viewPagerSetContentoffsetFrames; i++) {
CGFloat startTimeForAnimation = i * (keyFramesAnimatonDuration / viewPagerSetContentoffsetFrames);
CGPoint keyFrameContentOffset =
CGPointMake(currentOffset.x + eachXOffset * (i + 1),
currentOffset.y + eachYOffset * (i + 1));
[UIView addKeyframeWithRelativeStartTime:startTimeForAnimation
relativeDuration:durationForEachKeyFrameAnimation
animations:^{
[super setContentOffset:keyFrameContentOffset];
}];
}
} completion:NULL];
}
else {
[super setContentOffset:contentOffset];
}
}
else {
[super setContentOffset:contentOffset animated:animated];
}
[super setContentOffset:contentOffset animated:animated];
}
- (void)hippyBridgeDidFinishTransaction {