1

是否可以在应用程序范围内设置属性以使 iOS 应用程序内的转换速度加倍?

4

2 回答 2

10

应用范围?

尝试在支持层上为视图控制器的内容视图设置速度属性。speed=2 将是双速。您可能可以在所有视图控制器的 viewDidLoad 方法中设置它。

您也许还可以创建 UIWindow 的自定义子类,并让该窗口对象在 makeKeyWindow 之类的瓶颈方法中将其视图层上的速度属性设置为 2.0。您需要让所有应用程序的 UIWindow 对象都使用您的自定义类。我必须做一些挖掘才能弄清楚如何做到这一点。

##编辑:

或者,更好的主意是self.window.layer.speed = 2.0在创建窗口后在您的应用程序委托中设置,如@Costique 在下面的评论中所建议的那样。

请注意,这种方法将加速所有动画,而不仅仅是过渡和转场。如果您只想加快转场速度,则必须弄清楚如何仅针对这些动画。我不得不考虑一下。

于 2012-04-04T20:36:17.513 回答
3

Apple 没有简单的方法来改变这一点,因为它会使不同应用程序之间的转换过于异构。您可以将图层的速度加倍,但这会打乱其余动画的时间。最好的方法是使用 UIViewControler 上的类别来实现您自己的转换。

UIViewController+ShowModalFromView.h

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

@interface UIViewController (ShowModalFromView)
- (void)presentModalViewController:(UIViewController *)modalViewController fromView:(UIView *)view;
@end

UIViewController+ShowModalFromView.m

#import "UIViewController+ShowModalFromView.h"

@implementation UIViewController (ShowModalFromView)

- (void)presentModalViewController:(UIViewController *)modalViewController fromView:(UIView *)view {
    modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;

// Add the modal viewController but don't animate it. We will handle the animation manually
[self presentModalViewController:modalViewController animated:NO];

// Remove the shadow. It causes weird artifacts while animating the view.
CGColorRef originalShadowColor = modalViewController.view.superview.layer.shadowColor;
modalViewController.view.superview.layer.shadowColor = [[UIColor clearColor] CGColor];

// Save the original size of the viewController's view    
CGRect originalFrame = modalViewController.view.superview.frame;

// Set the frame to the one of the view we want to animate from
modalViewController.view.superview.frame = view.frame;

// Begin animation
[UIView animateWithDuration:1.0f
                 animations:^{
                     // Set the original frame back
                     modalViewController.view.superview.frame = originalFrame;
                 }
                 completion:^(BOOL finished) {
                     // Set the original shadow color back after the animation has finished
                     modalViewController.view.superview.layer.shadowColor = originalShadowColor;
                 }];
}

@end

这可以很容易地更改为使用您想要的任何动画过渡。希望这可以帮助!

于 2012-04-04T21:04:26.047 回答