我已经完成了与您描述的类似的操作,即更改 UINavigationController 中视图弹出和推送的默认动画。
这个想法是禁用对象的默认动画并将其替换为您自己的动画。我为 UINavigationController 创建了一个新类别,并使用了类似于下面的函数。
- (void) altAnimatePopViewControllerAnimated:(BOOL)animated
{
[CATransaction begin];
CATransition *transition;
transition = [CATransition animation];
transition.type = kCATransitionPush; // Use any animation type and subtype you like
transition.subtype = kCATransitionFromTop;
transition.duration = 0.3;
CATransition *fadeTrans = [CATransition animation];
fadeTrans.type = kCATransitionFade;
fadeTrans.duration = 0.3;
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
[[[[self.view subviews] objectAtIndex:0] layer] addAnimation:transition forKey:nil];
[[[[self.view subviews] objectAtIndex:1] layer] addAnimation:fadeTrans forKey:nil];
[self popViewControllerAnimated:YES];
[CATransaction commit];
}
使用只需使用代码
[self.navigationController altAnimatePopViewControllerAnimated:YES];
为了进行推送,只需创建另一个类似的功能并反转动画。
它并不完美,但它有效。当您选择不同的动画类型时,请使用组成导航栏/控制器的不同子视图来使其完美。
花了我相当大的精力想出这个,所以明智地使用它:)
******* 编辑
尝试用这个替换推送转换(自己没有尝试过):
CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
scale.duration = duration;
scale.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:.5f],
[NSNumber numberWithFloat:1.2f],
[NSNumber numberWithFloat:.85f],
[NSNumber numberWithFloat:1.f],
nil];
这会弹出一个窗口,即视图在调整到正确大小之前会更大。使用数组中的值来控制动画的曲线。