您的位置:首页 > 移动开发 > IOS开发

pushViewController自定义动画(转)

2014-04-20 22:42 316 查看


pushViewController自定义动画

Posted on 十二月 14, 2010 by tiger



 

 



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

- (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替换来改变样式。

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



 

 



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

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 动画