一些不错的动画效果---郭雪彬

一些比较实用简便的抖动和震动效果和控制器跳转渐变效果,具体什么效果自己试去,只需要调用相应方法,将你的控件传进去就可以。

   废话不多说,直接上代码:

-(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];
}

待续。。。  

原文地址:https://www.cnblogs.com/sixindev/p/4490632.html