Iphone 在自定义视图控制器转换中抑制导航推送动画
我将iOS 7中引入的新自定义视图控制器转换与UINavigationController结合使用。我实施Iphone 在自定义视图控制器转换中抑制导航推送动画,iphone,cocoa-touch,uinavigationcontroller,uikit,ios7,Iphone,Cocoa Touch,Uinavigationcontroller,Uikit,Ios7,我将iOS 7中引入的新自定义视图控制器转换与UINavigationController结合使用。我实施 -navigationController:animationControllerForOperation:fromViewController:toViewController: 在我的UINavigationControllerDelegate中,实现了UIViewControllerAnimatedTransitioning协议,自定义转换工作得非常出色 但是,我希望在按下视图控制
-navigationController:animationControllerForOperation:fromViewController:toViewController:
在我的UINavigationControllerDelegate
中,实现了UIViewControllerAnimatedTransitioning
协议,自定义转换工作得非常出色
但是,我希望在按下视图控制器时阻止导航栏中的shift动画。有趣的是,pop动画很好,导航项只是alpha淡入淡出,而不是移动。但是推送动画会将导航项从右侧移动
通过将-pushViewController:animated:
替换为-setViewControllers:animated:
,并将新的视图控制器添加到viewControllers
阵列中,我找到了部分解决方案。这将生成正确的alpha淡入淡出动画-第一次将视图控制器推到堆栈上时除外。后续的pop/push操作也可以
你知道如何达到这个效果吗?Calendar.app和Photos.app也实现了这一点,因此这应该是可能的(尽管这可能是使用集合视图时的一种特定行为)。我编写了一个解决方案,可以从导航栏子视图中删除所有位置动画:
@implementation UIView (FTNavigationBar)
static CGFloat leftMargin = 8;
- (void)removePushAnimation {
CAAnimation *animation = [self.layer animationForKey:@"position"];
if (animation) {
if ([animation isKindOfClass:CABasicAnimation.class] && ((CABasicAnimation*)animation).fromValue) {
CGPoint point = [((CABasicAnimation*)animation).fromValue CGPointValue];
CGFloat halfSuperWidth = [self superviewOfKind:FTNavigationBar.class].bounds.size.width / 2;
if ((fabs(point.x - halfSuperWidth) < 2 && fabs(self.center.x - halfSuperWidth) > 2) || fabs(point.x - self.frame.size.width/2 - leftMargin) < 2) {
self.layer.position = point;
}
}
[self.layer removeAnimationForKey:@"position"];
}
for (UIView *subview in [self subviews]) {
[subview removePushAnimation];
}
}
@end
实现UIView(FTNavigationBar)
静态CGFloat leftMargin=8;
-(void)removePushAnimation{
CAAnimation*animation=[self.layer animationForKey:@“position”];
if(动画){
if([animation iskindof class:CABasicAnimation.class]&((CABasicAnimation*)animation.fromValue){
CGPoint=[((cabasicanition*)动画.fromValue CGPointValue];
CGFloat halfSuperWidth=[self-superviewOfKind:FTNavigationBar.class].bounds.size.width/2;
如果((晶圆厂(点x-半超宽)<2和晶圆厂(自中心点x-半超宽)>2)| |晶圆厂(点x-自框架点尺寸点宽度/2-左边距)<2){
self.layer.position=点;
}
}
[self.layer removeAnimationForKey:@“位置”];
}
对于(UIView*子视图在[自子视图]中){
[子视图removePushAnimation];
}
}
@结束
我不知道您这里是否还有问题,但我无法重现。你能提供更多细节吗?当我使用
animationControllerForOperation
指定自定义转换时,动画会以我预期的方式影响我的内容,导航栏会淡入淡出(对于推送和弹出),它会淡入淡出,但也会进行移位动画。我会发布我的解决方法。