UIViewController的Push-Pop类动画,无需使用NavigationController

时间:2013-01-18 09:53:08

标签: iphone ios uinavigationcontroller uiviewanimation

我想在我的应用程序中实现 Push / Pop类型的动画。目前在我的申请中,我只是添加&使用addsubview&删除viewcontroller删除子视图没有任何动画。

添加导航控制器将是应用程序的一个重大变化,因为它将改变整个应用程序结构。有没有办法用导航控制器实现这种动画。

4 个答案:

答案 0 :(得分:1)

试试这个

首先给你的子视图一个框架

     secondview.frame=CGRectMake(330, 0, 320, 460);

然后当你添加它

   [self.view addSubView:secondview];

   [UIView beginAnimations:@"bringViewDown" context:nil];
   [UIView setAnimationDuration:0.2];
   firstview.frame=CGRectMake(-330, 0, 320, 460);
   secondview.frame=CGRectMake(0, 0, 320, 460);
   [UIView commitAnimations];

希望这会有所帮助.....

答案 1 :(得分:1)

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        viewSecond.frame = CGRectMake(330, 0, 320, 548);
    }


- (IBAction)onBtnClick:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    viewFirst.frame = CGRectMake(-330, 0, 320, 548);
    viewSecond.frame = CGRectMake(0, 0, 320, 548);
    [UIView commitAnimations];
}
- (IBAction)onBtnClick2:(id)sender
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    viewFirst.frame = CGRectMake(0, 0, 320, 548);
    viewSecond.frame = CGRectMake(330, 0, 320, 548);
    [UIView commitAnimations];
}

答案 2 :(得分:0)

实现自定义容器控制器参考会话102 - 在WWDC 2011中实现UIViewController遏制

答案 3 :(得分:0)

使用推送动画添加子视图

//push animation
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:transition forKey:nil];
[self addSubview:subView];

并删除带有流行动画的子视图

//pop animation
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.superview layer] addAnimation:animation forKey:@"SlideView"];
[self removeFromSuperview];