在视图控制器中点击导航栏按钮,实现导航栏按钮和页面的转场动画
//设置点击导航栏按钮事件
- (void)buttonAction:(UIButton *)button {
//取得导航项的父视图
UIView *superView = self.navigationItem.rightBarButtonItem.customView;
UIButton *button1 = (UIButton *)[superView viewWithTag:101];
UIButton *button2 = (UIButton *)[superView viewWithTag:102];
//将按钮的hidden值取反
button1.hidden = !button1.hidden;
button2.hidden = !button2.hidden;
//将视图的hidden值取反
_tableView.hidden = !_tableView.hidden;
_posterView.hidden = !_posterView.hidden;
//设置转场动画的值
UIViewAnimationTransition animation = button1.hidden ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight;
[self flipViewWithAnimation:animation WithView:superView];
[self flipViewWithAnimation:animation WithView:self.view];
}
//转场动画
- (void)flipViewWithAnimation:(UIViewAnimationTransition)animation WithView:(UIView *)view {
//开始动画
[UIView beginAnimations:nil context:nil];
//动画时间
[UIView setAnimationDuration:.35];
//转场动画
[UIView setAnimationTransition:animation forView:view cache:YES];
//结束动画
[UIView commitAnimations];
}