pushViewController自定义动画(转)

通过设置CATransition动画,实现pushViewController入栈时的自定义效果,包括ease-in-ease-out过渡,从顶部推入的样式。同时提供了另一种通过UIView动画改变frame,平滑滑动显示新页面的方法。
摘要由CSDN通过智能技术生成

pushViewController自定义动画

Posted on  十二月 14, 2010  by  tiger

屏幕快照 2010-12-14 下午05.45.06 屏幕快照 2010-12-14 下午05.45.50 屏幕快照 2010-12-14 下午05.46.04

要实现这样的效果就在入栈跳转的那个方法中添加代码,覆盖源代码:

- (IBAction)onClick{   
    secondView *mysec=[[secondView alloc] initWithNibName:@”secondView” bundle:nil];
    CATransition *transition = [CATransition animation];
    transition.duration = 1;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromTop;
    transition.delegate = self;
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController pushViewController:mysec animated:NO];
    [self.navigationController.view.layer addAnimation:transition forKey:nil];

    [mysec release];
}

注:transition.type = kCATransitionPush;
        transition.subtype = kCATransitionFromTop;分别表示跳转前页面和后出现的页面离开和出现方式,我们也可用kCATransitionMoveIn,kCATransitionReveal,kCATransitionFade替换来改变样式。

接下来实现另一种样式:如图

屏幕快照 2010-12-14 下午05.59.58 屏幕快照 2010-12-14 下午06.00.07 屏幕快照 2010-12-14 下午06.00.30

同样在入栈跳转的那个方法中添加代码,覆盖源代码:

- (IBAction)onClick{   
   

secondView *mysec=[[secondView alloc] initWithNibName:@”secondView” bundle:nil];
    mysec.view.frame = CGRectMake(0.0f, -480.0f, 320.0f, 960.0f);
    [self.navigationController pushViewController:mysec animated:NO];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.3];
    [UIView setAnimationDelegate:self];
    //controller.view.center = CGPointMake(160.0f, 240.0f);
    mysec.view.frame = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
    [UIView commitAnimations];
    [mysec release];

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值