2

我有一个在同一个视图控制器中有两个视图的转换类。这工作正常。我想将相同的转换应用于第二个视图控制器。我没有任何异常,但它不起作用......

当前的过渡代码是这样的:

自定义转换类

- (id)initWithBaseView:(UIView *)baseView firstView:(UIView *)firstView lastView:(UIView *)lastView
{
    if((self = [super init])) {
        self.view = baseView;
        self.originalView = firstView;
        self.nextView = lastView;
    }
    return self;
}

这是正在工作的代码:

单视图控制器类

- (IBAction)doTransition:(id)sender
{
    MyTransition *transition = [[MyTransition alloc] initWithBaseView:self.view 
                                                                          firstView:self.currentView 
                                                                           lastView:self.nextView];
    [transition buildAnimation];
}

我想实现这样的目标:

- (IBAction)doTransition:(id)sender
{
    NSLog(@"%s", __FUNCTION__);
    MyTransition *transition = [[MyTransition alloc] initWithBaseView:self.view
                                                                          firstView:self.currentView 
                                                                           lastView:secondView.lastView];
    [transition buildAnimation];
}
- (void)viewDidLoad
{
    NSLog(@"%s", __FUNCTION__);
    [super viewDidLoad];
    secondView = [[SecondViewController *) secondView initWithNibName:@"SecondViewController" bundle:nil];
}

第一个视图在第一个视图控制器中,下一个视图在第二个视图控制器中。

更新:

我已将 First VC 更新如下:

   - (void)viewDidLoad
    {
        NSLog(@"%s", __FUNCTION__);
        [super viewDidLoad];
        secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    }

- (IBAction)doTransition:(id)sender
{
    NSLog(@"%s", __FUNCTION__);
    MyTransition *transition = [[MyTransition alloc] initWithBaseView:self.view                                             firstView:self.currentView                                                   lastView:secondView.view];

    [transition buildAnimation];
}

记录第二个 VC 表明它没有被调用..

4

2 回答 2

2

我认为如果你尝试这样的事情它应该工作:

- (IBAction)doTransition:(id)sender
{
    NSLog(@"%s", __FUNCTION__);
    MyTransition *transition = [[MyTransition alloc] initWithBaseView:self.view
                                                                          firstView:self.currentView 
                                                                           lastView:secondView.view];
    [transition buildAnimation];
}
- (void)viewDidLoad
{
    NSLog(@"%s", __FUNCTION__);
    [super viewDidLoad];
    secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
}

如果我了解您要做什么,那么您应该能够在 SecondViewController 的视图上执行相同的动画,就像您使用常规视图一样。还是我错过了其他东西?

于 2013-02-08T01:11:56.907 回答
0

问题原来是我没有在它自己的 ViewController 中正确初始化 secondView。一旦我这样做了,过渡就会根据需要进行。

对于其他人,我使用的代码如下:

第一视图控制器:

- (void)viewDidLoad
{
    NSLog(@"%s", __FUNCTION__);
    [super viewDidLoad];

    secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

}

- (IBAction)clickOpenDoor:(id)sender
{

MyTransition *transition = [[MyTransition alloc] initWithBaseView:self.view
firstView:self.currentView                                               lastView:secondView.view];

    [transition buildAnimation];
}

第二个视图控制器:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(@"%s", __FUNCTION__);
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 350, 500)];
        tableView  = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 350, 500)];
        [view addSubview:tableView];
    }
于 2013-02-08T12:23:14.047 回答