在開發中,視圖切換會常常遇到,有時我們不是基於導航控制器的切換,但實際開發中,有時需要做成push效果,下面將如何?push和pop 預設動畫效果代碼執行個體:
一、push預設動畫效果
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
transition.delegate = self;
[self.contentView.layer addAnimation:transition forKey:nil];
[self.contentView addSubview:self.productDetailController.view];
註:self.contentView是工程中的UIView,self.productDetailController是工程中的controller
只需要把兩者替換成合適的內容即可用
二、pop預設動畫效果
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.view.superview.layer addAnimation:transition forKey:nil];
[self.view removeFromSuperview];
說明:.type 設定了主要的頁面切換顯示形式
.subtype 設定了頁面的旋轉 左右上下