一些不错的动画效果---郭雪彬
一些比较实用简便的抖动和震动效果和控制器跳转渐变效果,具体什么效果自己试去,只需要调用相应方法,将你的控件传进去就可以。
废话不多说,直接上代码:
-(void)shakeView:(UIView*)viewToShake
{
CGFloat t =2.0;
CGAffineTransform translateRight =CGAffineTransformTranslate(CGAffineTransformIdentity, t,0.0);
CGAffineTransform translateLeft =CGAffineTransformTranslate(CGAffineTransformIdentity,-t,0.0);
viewToShake.transform = translateLeft;
[UIView animateWithDuration:0.07 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{
[UIView setAnimationRepeatCount:2.0];
viewToShake.transform = translateRight;
} completion:^(BOOL finished){
if(finished){
[UIView animateWithDuration:0.05 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
viewToShake.transform =CGAffineTransformIdentity;
} completion:NULL];
}
}];
}
-(void)earthquake:(UIView*)itemView
{
CGFloat t =2.0;
CGAffineTransform leftQuake =CGAffineTransformTranslate(CGAffineTransformIdentity, t,-t);
CGAffineTransform rightQuake =CGAffineTransformTranslate(CGAffineTransformIdentity,-t, t);
itemView.transform = leftQuake; // starting point
[UIView beginAnimations:@"earthquake" context:(__bridge void *)(itemView)];
[UIView setAnimationRepeatAutoreverses:YES];// important
[UIView setAnimationRepeatCount:5];
[UIView setAnimationDuration:0.07];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(earthquakeEnded:finished:context:)];
itemView.transform = rightQuake;// end here & auto-reverse
[UIView commitAnimations];
}
//下面是视图跳转渐变效果,在手机思埠发现的,还不错,顺便分享下给大家
//使用方法:把你初始化好的Controller传进去就可以了,方便实用。
- (void)pushFadeViewController:(UIViewController *)viewController
{
CATransition *transition = [CATransition animation];
transition.duration = 1.2f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.view.layer addAnimation:transition forKey:nil];
[self pushViewController:viewController animated:NO];
}
- (void)fadePopViewController
{
CATransition *transition = [CATransition animation];
transition.duration = 1.2f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.view.layer addAnimation:transition forKey:nil];
[self popViewControllerAnimated:NO];
}
待续。。。
作者:SIBU iOS DEV
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

浙公网安备 33010602011771号