ios6中视图控制器之间的自定义转换

时间:2013-01-29 20:42:05

标签: uitableview uiviewcontroller ios6

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

当前的转换代码如下:

自定义过渡类

- (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 View位于第一个View Controller中,下一个视图位于第二个视图控制器中..

更新:

我已按如下方式更新了第一个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显示它未被调用..

2 个答案:

答案 0 :(得分: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的视图上执行相同的动画,就像你使用常规视图一样。或者我错过了其他什么?

答案 1 :(得分:0)

问题结果是我没有在自己的ViewController中正确初始化secondView。一旦我这样做,过渡就会按需运作。

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

FirstViewController:

- (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];
    }