如何加速iOS转换和segues?

时间:2012-04-04 19:40:18

标签: objective-c ios core-animation

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

2 个答案:

答案 0 :(得分:8)

应用范围?

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

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

答案 1 :(得分: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

这可以轻松更改为使用您想要的任何动画转换。希望这有帮助!