1

2 つの ViewController を使用して新しいプロジェクトを作成し、ViewControllerLTR ではなく右から左にプッシュするクラスをインポートしましたが、それを使用できません。pushViewController内部で UIRightToLeft.m が呼び出されていないことがわかり、その理由がわかりません。私の主な目標は、それを RTL アニメで動作させることです。

#import "UIRightToLeft.h"

@implementation UIRightToLeft

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithRootViewController:rootViewController];
    if (!self)
        return nil;
    return self;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    NSLog(@"pushViewController");
    // Add the viewController and a fake controller without animation. Then pop the fake controller with animation.
    UIViewController *fakeController = [[UIViewController alloc] init] ;
    [super setViewControllers:[[self viewControllers] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:viewController, fakeController, nil]] animated:NO];
    [super popViewControllerAnimated:animated];
}

- (void)popViewControllerAnimatedStep2:(UIViewController *)viewController
{
    // Push the new top controller with animation
    [super pushViewController:viewController animated:YES];
    // Remove the view that should have been popped
    NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
    [arr removeObjectAtIndex:[[self viewControllers] count]-2];
    [super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
}

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    NSLog(@"popViewControllerAnimated");

    if (animated)
    {
        // Save the controller that should be on top after this pop operation
        UIViewController *newTopController = [[self viewControllers] objectAtIndex:[[self viewControllers] count]-2];
        // Remove it from the stack. Leave the view that should be popped on top
        NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
        [arr removeObjectAtIndex:[[self viewControllers] count]-2];
        [super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
        // Schedule the next step
        [self performSelector:@selector(popViewControllerAnimatedStep2:) withObject:newTopController afterDelay:0];
        return [arr objectAtIndex:[arr count]-1];
    }
    return [super popViewControllerAnimated:NO];
}

@end

ViewController.m:

#import "ViewController.h"
#import "UIRightToLeft.h"
#import "SecondViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)pressMe:(UIButton *)sender {
    SecondViewController *next = [[SecondViewController alloc]init];
    [self.navigationController pushViewController:next animated:YES];    
}

@end

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)pressMe:(UIButton *)sender;

@end

(私の場合、プッシュViewControllerで2番目にドラッグされたボタンは1つだけです)ViewController

4

1 に答える 1

1

エラー ログを確認した後、実際にはナビゲーション コントローラーのサブクラス UIRightToLeft が必要だと思います。

ストーリーボードを使用している場合は、ナビゲーション コントローラーを選択し、カスタム クラスを UIRightToLeft に設定します。

于 2013-01-03T14:19:11.967 に答える