the*_*ory 7 cocoa-touch core-animation uiview uinavigationcontroller uiviewanimationtransition
继苹果公司的建议,我通过把后续调用链接的UIView动画-animationWithDuration:animation:中的completion:另一个呼叫的块aanimateWithDuration:animation:completion:,像这样:
[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
// Scale the controllers' views down.
self.view.transform = CGAffineTransformScale(self.view.transform, 0.8, 0.8);
} completion:^(BOOL finished) {
// Transition to the new view and push on the new view controller.
[UIView transitionWithView:self.view duration:1 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionTransitionFlipFromLeft animations:^{
[self pushViewController:viewController animated:NO];
} completion:^(BOOL finished) {
[UIView animateWithDuration:scaleDuration delay:0 options:UIViewAnimationOptionCurveLinear animations:
^{
// Scale back to the original size.
self.view.transform = CGAffineTransformScale(self.view.transform, 1.25, 1.25);
} completion:nil];
}];
}];
Run Code Online (Sandbox Code Playgroud)
动画都执行正确的顺序,但它们之间存在微小的延迟,特别是在-transitionWithView:duration:options:animations:completion:通话之前.如何平滑动画步骤之间的过渡?
旁白: \n您以这种方式滥用导航控制器
有什么特殊原因吗?\xe2\x80\x99 不能presentViewController:animated:completion:将其过渡样式设置为 吗UIModalTransitionStyleFlipHorizontal?
回到你的问题:
\n\nI\xe2\x80\x99m 非常确定口吃来自一个简单的事实,即pushViewController:animated:隐式必须加载要推送的视图控制器的视图,并且这需要一些时间。
因此,如果您无法使用presentViewController:animated:completion:(或presentModalViewController:animated:如果您必须支持iOS 4)方法,我\xe2\x80\x99d鼓励您尝试以下方法:
// ensure the view is already loaded when you invoke `pushViewController:animated:`\n[viewController view];\n\n// there is no strict need to calculate those in situ, so we do it up front\nCGAffineTransform originalTransform = self.view.transform;\nCGAffineTransform downscalingTransform = CGAffineTransformScale(originalTransform, 0.8, 0.8);\n\n// I found it hard to read the block-in-a-block-in-a... while editing here, so I've taken them apart:\nvoid (^scaleDownAnimation)() = ^{\n self.view.transform = downscalingTransform;\n};\n\nvoid (^restoreScaleAnimation)() = ^{\n self.view.transform = originalTransform;\n};\n\nvoid (^pushControllerAnimation)() = ^{\n [self pushViewController:viewController animated:NO];\n};\n\nvoid (^pushAnimationCompletion)(BOOL) = ^(BOOL unused) {\n [UIView animateWithDuration:scaleDuration\n delay:0\n options:UIViewAnimationOptionCurveLinear\n animations:restoreScaleAnimation\n completion:nil];\n};\n\nvoid (^downscaleCompletion)(BOOL) = ^(BOOL unused){\n UIViewAnimationOptions linearFlipFromLeft = UIViewAnimationOptionCurveLinear | UIViewAnimationOptionTransitionFlipFromLeft;\n [UIView transitionWithView:self.view\n duration:1\n options:linearFlipFromLeft\n animations:pushControllerAnimation\n completion:pushAnimationCompletion];\n};\n\n[UIView animateWithDuration:scaleDuration\n delay:0\n options:UIViewAnimationOptionCurveEaseIn\n animations:scaleDown\n completion:downscaleCompletion];\nRun Code Online (Sandbox Code Playgroud)\n\n请注意,牛肉位于前六行内,其余的只是为了完整性。
\n| 归档时间: |
|
| 查看次数: |
1738 次 |
| 最近记录: |