动画UINavigationController的“后退”按钮 [英] Animating UINavigationController's 'back' button

查看:120
本文介绍了动画UINavigationController的“后退”按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航控制器的层次结构中的视图控制器上有一个自定义按钮,当按下该按钮时,会弹出可见的视图控制器。

I have a custom button on a view controller in the navigation controller's heirarchy, that when pressed, pops the visible view controller.

我想使用UIView的转换属性来设置视图控制器的关闭动画。它可以工作,但如果我使用`popViewControllerAnimated:YES',动画的默认左侧幻灯片仍然存在,尽管我的自定义转换也可以。

I want to use UIView's transform property to animate the closing of the view controller. It works, but if I use `popViewControllerAnimated:YES', the default left slide of the animation is still there, though my custom transform also works.

如果我设置 popViewControllerAnimated:NO 它根本不动画任何内容。

If I set popViewControllerAnimated:NO it doesn't animate anything at all.

我还研究过使用 CATransition 当我有 popViewControllerAnimated 设置为,但没有缩放效果是公共API的一部分,我不想使用私有效果。自定义过滤器也不适用于iPhone,仅适用于OS X.

I also looked into using CATransition which works when I have popViewControllerAnimated set to NO, but there isn't a "zoom" effect that's part of the public API, and I don't want to use the private effect. Custom filters are also not available for iPhone, only OS X.

所以我想我的问题是:

1)有没有办法在默认转换中删除左侧幻灯片,但仍然使用转换进行自定义动画?

1) Is there a way to remove the the left slide in the default transition yet still have a custom animation using transform?

2)使用自定义过滤器的一些方法 CATransition

2) Some way to use a custom filter for CATransition?

3)如果我使用私有用于缩放效果的API有多大可能让Apple在拒收箱中丢弃我的应用程序?

3) If I use a private API for the zoom effect how likely will Apple toss my app in the rejection bin?

有没有人有我忽略的解决方案?

Does anyone have a solution I'm overlooking?

推荐答案

我做了类似你所描述的事情,即在UINavigationController中更改pop和push of view的默认动画。

I've done something similar to what you describe, i.e. change the default animation for pop and push of view in UINavigationController.

这个想法是禁用对象的默认动画并用你自己的动画替换它。我为UINavigationController创建了一个新类别,并使用了类似下面的函数。

The idea is to disable the default animation for the object and replace it with your own animation. I've created a new category for UINavigationController and used a function similar to the one below.

 - (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];

为了进行推送,只需创建另一个类似的功能并反转动画。

In order to do a push just create another similar function and reverse the animation.

它并不完美,但它有效。当您选择不同的动画类型时,可以使用构成导航栏/控制器的不同子视图来完美地使用它。

It's not perfect but it works. When you choose different animation types play around with the different subviews composing the navigation bar/controller to get it perfect.

拿出我的白色来想出这个,所以明智地使用它:)

Took my quite a white to come up with this, so use it wisely :)

*******编辑

尝试用此替换推送转换(我自己没试过):

Try replacing the push transition with this (Didn't try it myself):

  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];

这会弹出一个,即视图在结算到合适大小之前会更大。使用数组中的值来控制动画的曲线。

This will do a pop in, i.e. the view will be bigger before it settles to the right size. Play with the values in the array to control the curve of the animation.

这篇关于动画UINavigationController的“后退”按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆