1

iOSアプリ内の遷移の速度を2倍にするために、アプリケーション全体でプロパティを設定することは可能ですか?

4

2 に答える 2

10

アプリケーション全体?

ビュー コントローラーのコンテンツ ビューのバッキング レイヤーで速度プロパティを設定してみてください。speed=2 は倍速になります。おそらく、すべてのView ControllerのviewDidLoadメソッドでこれを設定できます。

また、UIWindow のカスタム サブクラスを作成し、makeKeyWindow などのボトルネック メソッドでそのウィンドウ オブジェクトのビュー レイヤーの速度プロパティを 2.0 に設定することもできます。アプリのすべての UIWindow オブジェクトでカスタム クラスを使用する必要があります。それを行う方法を理解するには、いくつかの掘り下げを行う必要があります。

##編集:

または、self.window.layer.speed = 2.0以下のコメントで @Costique が提案しているように、ウィンドウを作成した後にアプリのデリゲートに設定することをお勧めします。

このアプローチは、トランジションとセグエだけでなく、すべてのアニメーションを高速化することに注意してください。セグエのみを高速化する場合は、それらのアニメーションだけをターゲットにする方法を考え出す必要があります。私はそれについて考えなければならないでしょう。

于 2012-04-04T20:36:17.513 に答える
3

異なるアプリ間で遷移が異質になりすぎるため、Apple はそれを変更する簡単な方法を持っていません。レイヤーの速度を 2 倍にすることもできますが、そうすると残りのアニメーションのタイミングが台無しになります。最良の方法は、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 に答える