標籤:os io for 問題 代碼 時間 res type
效果:視圖從大--小縮放顯示/小--大 (只是比例問題)
方法1.直接show出view的時候:
把下面的這段代碼加到viewController或者view出現的時候就OK
self.view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);//將要顯示的view按照正常比例顯示出來
[UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //InOut 表示進入和出去時都啟動動畫
[UIView setAnimationDuration:0.5f];//動畫時間
self.view.transform=CGAffineTransformMakeScale(0.01f, 0.01f);//先讓要顯示的view最小直至消失
[UIView commitAnimations]; //啟動動畫
//相反如果想要從小到大的顯示效果,則將比例調換
//UIGraphicsGetCurrentContext 裡面東西很豐富。
——————————————————————————————————————————
方法2.push一個viewController時:
把下面的代碼加到push的方法裡面就OK
CATransition *myTranstiton = [CATransition animation];
myTranstiton.duration = 0.5;
myTranstiton.type = kCATransitionFade;
//myTranstiton.subtype = kCATransitionFromTop;
[self.view.superview.layer addAnimation:myTranstiton forKey:nil ];
MainViewController * _mainViewController=[[MainViewController alloc] init];
[self presentModalViewController:_mainViewController animated:NO];