1

是否可以(完全)使用自定义 AnimationTransition 加载 XIB?

我所做的是创建一个“覆盖”屏幕的动画,我想要的是在该动画完成播放后,我希望它显示新的 XIB。

我似乎无法找到任何适当的解决方案......有什么想法吗?

为了更清楚:按一个按钮-->播放动画(封面屏幕)-->加载XIB。


再一次问好!是的,你描述的最后一种方式就是我正在做的方式。我有两个 UIView(可能已经错了),它们在每一侧都被放置在边界之外,(如 x.-160.y.0 和 x.320y.0)

-(IBAction) leftDoor{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    closeDoor1.center = CGPointMake( closeDoor1.center.x +160, closeDoor1.center.y);


    [UIView commitAnimations];

 } 


-(IBAction) rightDoor{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    closeDoor2.center = CGPointMake( closeDoor2.center.x -160, closeDoor2.center.y);

    [UIView commitAnimations];
}

所以,我要做的不是“拆分”当前视图然后打开一个新的 XIB,我正在寻找的效果是“关门”效果,这就是我使用 UIView 的原因(以为我将图形放在顶部其中,比如两个 ImageView)。然后,为了加载新的 XIB ......这是我真正困惑的地方。我尝试的第一种方法是制作三个 IBAction,包括我上面提到的两个,然后将所有三个(多个操作)应用到一个按钮。所以为了切换视图,我做了这样的事情:`-(IBAction) newViewDisplay:(id)sender{

theView *newViewController = [[theView alloc]
                                      initWithNibName:@"theView" bundle:nil]; 

[self.view addSubview:newViewController.view];

} `

正如你所说,这可能超出了我的想象,但如果我只是得到一些指示,我会步行数英里来完成这项工作。它真的会让我的应用程序焕然一新。非常感谢您花时间回答我的问题,一切顺利/安迪

4

1 回答 1

2

你用什么遮住屏幕?

这样想,(听起来)你有 2 个视图,旧的和新的存储在这个 xib 中。动画是次要的。

您需要加载新视图,然后将其显示(可以在屏幕外),然后将其动画(移动)到您想要的位置。如果你想把它分成两部分,一个在屏幕底部,一个在屏幕顶部,然后在中间相遇,我认为这既复杂又超出你的技能水平。(在这里不要刻薄)。

如果您尝试按照描述进行拆分动画,则可以完成,但您需要“伪造”。这将涉及拍摄“屏幕截图”(各种),拆分它,移动这两个图像以便它们与动画相遇,加载下面的视图,然后删除图像。棘手的东西。

你必须有这种动画吗?

如果您可以发布您拥有的代码,我可以为您重新排列并添加它。

不过,您需要澄清您到底想要做什么。

更新 3:我为自动反转添加了另一个选项。

//您可以将两扇门添加到一个动画块中。

    //Create an animation block. Ease Out is better for this animation but you can change it.
[UIView animateWithDuration:1.0 delay:0.0 options:(UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAutoreverse) animations:^{
    closeDoor1.center = CGPointMake( closeDoor1.center.x +160, closeDoor1.center.y);
    closeDoor2.center = CGPointMake( closeDoor2.center.x -160, closeDoor2.center.y);

}completion:^(BOOL finished){
    if (finished) {
            //When finished, create the VC if it doesn't exist, and insert it below the 'closed door'.

        if (newViewController == nil) {
            UIViewController *newViewController = [[UIViewController alloc] initWithNibName:@"theView" bundle:nil]; 
        }

        [self.view insertSubview:newViewController.view belowSubview: closeDoor2];;
        [self.closeDoor1 removeFromSuperview];
        [self.closeDoor2 removeFromSuperview];

    }
}];
于 2011-05-30T00:13:02.293 回答