1

我想在我的应用程序中实现Push/Pop 类型的动画。目前在我的应用程序中,我只是使用 addsubview 和 removesubview 添加和删除视图控制器,没有任何动画。

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

4

4 回答 4

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];
}
于 2013-01-18T10:29:52.167 回答
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];

希望这可以帮助.....

于 2013-01-18T10:08:31.113 回答
0

实施自定义容器控制器请参阅 Session 102 - 在 WWDC 2011 中实施 UIViewController Containment

于 2013-01-18T10:52:21.850 回答
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];
于 2014-12-12T08:49:18.167 回答