//翻頁效果動畫左邊
[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
[UIView commitAnimations];
//翻頁效果動畫右邊
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaSEOut];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
//layer動畫,從上到下模糊
CATransition *animation = [CATransition animation];
[animation setDuration:2.0f];
[animation setFillMode:kCAFillModeForwards];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[self.navigationController.navigationBar.layer addAnimation:animation forKey:nil];
//折頁效果動畫
[UIView animateWithDuration:0.35f animations:^
/**
* @see http://donbe.blog.163.com/blog/static/138048021201061054243442/
* @param transform 形變屬性(結構體),可以利用這個屬性去對view做一些翻轉或者縮放.詳解請猛戳↑URL.
* @method valueWithCATransform3D: 此方法需要一個CATransform3D的結構體.一些非詳細的講解可以看下面的URL
* @see http://blog.csdn.net/liubo0_0/article/details/7452166
self.navigationController.view.transform = CGAffineTransformMakeScale(0.001, 0.001);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
// 向右旋轉45°縮小到最小,然后再從小到大推出.
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.70, 0.40, 0.80)];
/**
* 其他效果:
* 從底部向上收縮一半后彈出
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0)];
* 從底部向上完全收縮后彈出
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 1.0, 0.0, 0.0)];
* 左旋轉45°縮小到最小,然后再從小到大推出.
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.50, -0.50, 0.50)];
* 旋轉180°縮小到最小,然后再從小到大推出.
* animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.1, 0.2, 0.2)];
animation.duration = 2;
animation.repeatCount = 1;
[self.navigationController.view.layer addAnimation:animation forKey:nil];
completion:^(BOOL finished)
[UIView animateWithDuration:0.35f animations:^
self.navigationController.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
}];
//從下到上模糊推出
CATransition *animation = [CATransition animation];
[animation setDuration:1.0f];
[animation setType:kCATransitionReveal];
[animation setSubtype:kCATransitionFromTop];
[animation setFillMode:kCAFillModeForwards];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[self.navigationController.navigationBar.layer addAnimation:animation forKey:nil];
//旋轉動畫
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI) * 2];
rotationAnimation.duration = 0.35f;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.toValue = [NSNumber numberWithFloat:0.0];
scaleAnimation.duration = 0.35f;
scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = 2.35f;
animationGroup.autoreverses = YES;
animationGroup.repeatCount = 1;
animationGroup.animations =[NSArray arrayWithObjects:rotationAnimation, nil];
[self.navigationController.view.layer addAnimation:animationGroup forKey:@"animationGroup"];
[UIView commitAnimations];
CATransition *animation = [CATransition animation];
[animation setDuration:0.8];
/* 各種動畫效果*/
/* type類型 */ /*這里要注意不用私有方法*/
pageCurl 向上翻一頁
pageUnCurl 向下翻一頁
rippleEffect 滴水效果
suckEffect 收縮效果,如一塊布被抽走
cube 立方體效果
oglFlip 上下翻轉效果
[animation setType: kCATransitionReveal];
/* 動畫方向*/
/* SubType類型 */
kCATransitionFade淡出
kCATransitionMoveIn覆蓋原圖
kCATransitionPush推出
kCATransitionReveal底部顯出來
也可以有四種類型:
kCATransitionFromRight;
kCATransitionFromLeft
kCATransitionFromTop;
kCATransitionFromBottom
[animation setSubtype: kCATransitionFromBottom];
/* 動畫的開始與結束的快慢*/
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.navigationController.self.view.layer addAnimation:animation forKey:nil];
//這里應用場景是已經有2個viewController插入要的self.view上
[self.view insertSubview:self.blueController.view atIndex:0];
[self.view insertSubview:self.yellowController.view atIndex:1];
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//UIView開始動畫,第一個參數是動畫的標識,第二個參數附加的應用程序信息用來傳遞給動畫代理消息
[UIView beginAnimations:@"animation" context:nil];
//動畫持續時間
[UIView setAnimationDuration:1.25];
//設置動畫的回調函數,設置后可以使用回調方法
[UIView setAnimationDelegate:self];
//設置動畫曲線,控制動畫速度
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
//設置動畫方式,并指出動畫發生對象
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];//cache
/*cache
如果是YES,那么在開始和結束圖片視圖渲染一次并在動畫中創建幀;否則,視圖將會在每一幀都渲染。例如緩存,你不需要在視圖轉變中不停的更新,你只需要等到轉換完成再去更新視圖。
//設置動畫重復
[UIView setAnimationRepeatCount:5.0];
//提交UIView動畫 結束動畫
[UIView commitAnimations];
//開始一個動畫塊
[UIView beginAnimations:@"animationID" context:nil];
//設置動畫塊中的動畫持續時間(用秒)
[UIView setAnimationDuration:1.5f];
//設置動畫塊中的動畫屬性變化的曲線
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
/*變化曲線還有
( UIViewAnimationCurveEaseInOut, // slow at beginning and end
UIViewAnimationCurveEaseIn, // slow at beginning
UIViewAnimationCurveEaseOut, // slow at end
UIViewAnimationCurveLinear)
//設置動畫塊中的動畫效果是否自動重復播放。
[UIView setAnimationRepeatAutoreverses:NO];
//設置動畫在動畫模塊中的重復次數
//setAnimationRepeatCount:
//設置動畫消息的代理。
[UIView setAnimationDelegate:self];
/* UIView動畫的代理方法
// [UIView
// //設置消息給動畫代理當動畫開始的時候
// setAnimationWillStartSelector:@selector(resizeAnimationWillStart:context:)];
// [UIView
// //設置消息給動畫代理當動畫停止的時候
// setAnimationDidStopSelector:@selector(resizeAnimationDidStop:finished:context:)];
//將效果作用在指定的view
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
效果還有(UIViewAnimationTransitionFlipFromLeft,UIViewAnimationTransitionFlipFromRight,UIViewAnimationTransitionCurlUp,UIViewAnimationTransitionCurlDown)
//顯示在最前面
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
//結束動畫
[UIView commitAnimations];
新聞熱點
疑難解答