必威-必威-欢迎您

必威,必威官网企业自成立以来,以策略先行,经营致胜,管理为本的商,业推广理念,一步一个脚印发展成为同类企业中经营范围最广,在行业内颇具影响力的企业。

我是搬运工必威:

2019-09-16 00:01 来源:未知
#import <UIKit/UIKit.h>float radiansForDegrees(int degrees);@interface UIView (Animation)// 位移- moveTo:destination duration:secs option:(UIViewAnimationOptions)option;- moveTo:destination duration:secs option:(UIViewAnimationOptions)option delegate:delegate callback:method;- raceTo:destination withSnapBack:withSnapBack;- raceTo:destination withSnapBack:withSnapBack delegate:delegate callback:method;// 形变/** * 旋转 */- rotate:degrees secs:secs delegate:delegate callback:method;/** * 缩放 */- scale:secs x:scaleX y:scaleY delegate:delegate callback:method;/** * 顺时针旋转 * * @param secs 动画执行时间 */- spinClockwise:secs;/** * 逆时针旋转 * * @param secs 动画执行时间 */- spinCounterClockwise:secs;/** * 反翻页效果 * * @param secs 动画执行时间 */- curlDown:secs;/** * 视图翻页后消失 * * @param secs 动画执行时间 */- curlUpAndAway:secs;/** * 旋转缩放到一点后消失 * * @param secs 动画执行时间 */- drainAway:secs;/** * 将视图改变到一定透明度 * * @param newAlpha alpha * @param secs 动画执行时间 */- changeAlpha:newAlpha secs:secs;/** * 改变透明度结束动画后还原 * * @param secs alpha * @param continuously 是否循环 */- pulse:secs continuously:continuously;/** * 以渐变方式添加子控件 * * @param subview 需要添加的子控件 */- addSubviewWithFadeAnimation:subview;@end

#import "UIView+Animation.h"// Very helpful functionfloat radiansForDegrees(int degrees) { return degrees * M_PI / 180;}@implementation UIView (Animation)#pragma mark - Moves- moveTo:destination duration:secs option:(UIViewAnimationOptions)option { [self moveTo:destination duration:secs option:option delegate:nil callback:nil];}- moveTo:destination duration:secs option:(UIViewAnimationOptions)option delegate:delegate callback:method { [UIView animateWithDuration:secs delay:0.0 options:option animations:^{ self.frame = CGRectMake(destination.x,destination.y, self.frame.size.width, self.frame.size.height); } completion:^(BOOL finished) { if (delegate != nil) {#pragma clang diagnostic push#pragma clang diagnostic ignored "-Warc-performSelector-leaks" [delegate performSelector:method];#pragma clang diagnostic pop } }];}- raceTo:destination withSnapBack:withSnapBack { [self raceTo:destination withSnapBack:withSnapBack delegate:nil callback:nil];}- raceTo:destination withSnapBack:withSnapBack delegate:delegate callback:method { CGPoint stopPoint = destination; if (withSnapBack) { // Determine our stop point, from which we will "snap back" to the final destination int diffx = destination.x - self.frame.origin.x; int diffy = destination.y - self.frame.origin.y; if (diffx < 0) { // Destination is to the left of current position stopPoint.x -= 10.0; } else if (diffx > 0) { stopPoint.x += 10.0; } if (diffy < 0) { // Destination is to the left of current position stopPoint.y -= 10.0; } else if (diffy > 0) { stopPoint.y += 10.0; } } // Do the animation [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{ self.frame = CGRectMake(stopPoint.x, stopPoint.y, self.frame.size.width, self.frame.size.height); } completion:^(BOOL finished) { if (withSnapBack) { [UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.frame = CGRectMake(destination.x, destination.y, self.frame.size.width, self.frame.size.height); } completion:^(BOOL finished) {#pragma clang diagnostic push#pragma clang diagnostic ignored "-Warc-performSelector-leaks"[delegate performSelector:method];#pragma clang diagnostic pop }]; } else {#pragma clang diagnostic push#pragma clang diagnostic ignored "-Warc-performSelector-leaks" [delegate performSelector:method];#pragma clang diagnostic pop } }]; }#pragma mark - Transforms- rotate:degrees secs:secs delegate:delegate callback:method { [UIView animateWithDuration:secs delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.transform = CGAffineTransformRotate(self.transform, radiansForDegrees; } completion:^(BOOL finished) { if (delegate != nil) {#pragma clang diagnostic push#pragma clang diagnostic ignored "-Warc-performSelector-leaks" [delegate performSelector:method];#pragma clang diagnostic pop } }];}- scale:secs x:scaleX y:scaleY delegate:delegate callback:method { [UIView animateWithDuration:secs delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.transform = CGAffineTransformScale(self.transform, scaleX, scaleY); } completion:^(BOOL finished) { if (delegate != nil) {#pragma clang diagnostic push#pragma clang diagnostic ignored "-Warc-performSelector-leaks" [delegate performSelector:method];#pragma clang diagnostic pop } }];}- spinClockwise:secs { [UIView animateWithDuration:secs/4 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.transform = CGAffineTransformRotate(self.transform, radiansForDegrees; } completion:^(BOOL finished) { [self spinClockwise:secs]; }];}- spinCounterClockwise:secs { [UIView animateWithDuration:secs/4 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.transform = CGAffineTransformRotate(self.transform, radiansForDegrees; } completion:^(BOOL finished) { [self spinCounterClockwise:secs]; }];}#pragma mark - Transitions- curlDown:secs { [UIView transitionWithView:self duration:secs options:UIViewAnimationOptionTransitionCurlDown animations:^ { [self setAlpha:1.0]; } completion:nil];}- curlUpAndAway:secs { [UIView transitionWithView:self duration:secs options:UIViewAnimationOptionTransitionCurlUp animations:^ { [self setAlpha:0]; } completion:nil];}- drainAway:secs { self.tag = 20; [NSTimer scheduledTimerWithTimeInterval:secs/50 target:self selector:@selector(drainTimer:) userInfo:nil repeats:YES];}- drainTimer:timer { CGAffineTransform trans = CGAffineTransformRotate(CGAffineTransformScale(self.transform, 0.9, 0.9),0.314); self.transform = trans; self.alpha = self.alpha * 0.98; self.tag = self.tag - 1; if (self.tag <= 0) { [timer invalidate]; [self removeFromSuperview]; }}#pragma mark - Effects- changeAlpha:newAlpha secs:secs { [UIView animateWithDuration:secs delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ self.alpha = newAlpha; } completion:nil];}- pulse:secs continuously:continuously { [UIView animateWithDuration:secs/2 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ // Fade out, but not completely self.alpha = 0.3; } completion:^(BOOL finished) { [UIView animateWithDuration:secs/2 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ // Fade in self.alpha = 1.0; } completion:^(BOOL finished) { if (continuously) { [self pulse:secs continuously:continuously]; } }]; }];}#pragma mark - add subview- addSubviewWithFadeAnimation:subview { CGFloat finalAlpha = subview.alpha; subview.alpha = 0.0; [self addSubview:subview]; [UIView animateWithDuration:0.2 animations:^{ subview.alpha = finalAlpha; }];}@end

ps:看到这些基本效果还是比较不错的自己留着,我是搬运工!!!

TAG标签:
版权声明:本文由必威发布于必威-编程,转载请注明出处:我是搬运工必威: