pushViewController自定义动画(转)

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

}

你可能感兴趣的:(pushViewController自定义动画(转))