水柱动画

#import<UIKit/UIKit.h>

@interface SDmoreCicle : UIView

//水柱的实现

+(instancetype)ViewWithCicle:(CGRect)rect;

-(instancetype)initWithFrame:(CGRect)frame;

@end

#import "SDmoreCicle.h"

@implementation SDmoreCicle

+(instancetype)ViewWithCicle:(CGRect)rect

{

  return [[self alloc] initWithFrame:rect];

}

-(instancetype)initWithFrame:(CGRect)frame

{

    return [super initWithFrame:frame];

}

-(void)createCicle:(NSSet *)touches

{

    //第一次触碰

    UITouch *touch = [touches anyObject];

    //获取触碰的点

    CGPoint point = [touch locationInView:self];

    //初始化层

    CALayer *layer = [CALayer layer];

    //设置层是尺寸

    layer.frame = CGRectMake(point.x-1, point.y-1, 10, 10);

        //设置水柱的颜色

    layer.borderColor = [UIColor colorWithRed:arc4random()%243/64.0 green:arc4random()%230/100.0 blue:arc4random()%89/200.0 alpha:1].CGColor;    //设置水柱的边框宽度

    layer.borderWidth = 0.5;

    //设置水柱的倒圆角

    layer.cornerRadius = 5;

    //设置动画

    [self setAnimation:layer];

        [self.layer addSublayer:layer];

    }

-(void)setAnimation:(CALayer *)layer

{

    const int max = 20;

    if (layer.transform.m11 < max)

{

      //3D动画

      [layer setTransform:CATransform3DScale(layer.transform, 1.1, 1.1, 1.0)];        //动画延时

        //_cmd获取当前方法的名称

        [self performSelector:_cmd withObject:layer afterDelay:0.03];

    } else {

        //删除layer

        [layer removeFromSuperlayer];

    }

}

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event

{

    [self createCicle:touches];

}

-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event

{

[self createCicle:touches];

}

@end

#import<UIKit/UIKit.h>

#import "SDmoreCicle.h"

@interface ViewController : UIViewController

@end

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor grayColor];

[self.view addSubview:[SDmoreCicle ViewWithCicle:self.view.frame]];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

效果图:


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Quartz2D以及drawRect的重绘机制字数1487 阅读21 评论1 喜欢1一、什么是Quartz2D Q...
    PurpleWind阅读 810评论 0 3
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,147评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,573评论 6 30
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 838评论 0 0
  • 一:在ViewController中实例化MLPickerScrollView完成代理<MLPickerScrol...
    欧大帅Allen阅读 6,955评论 1 9