zoukankan      html  css  js  c++  java
  • 点击动画

    #import "ViewController.h"

    #import "SDmoreCircle.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

    //    背景色

        self.view.backgroundColor=[UIColor lightGrayColor];

        

        [self.view addSubview:[SDmoreCircle ViewWithCircle:self.view.frame]];

        

    }

    #import <UIKit/UIKit.h>

    @interface SDmoreCircle : UIView

    //

    +(instancetype)ViewWithCircle:(CGRect)rect;

    -(instancetype)initWithFrame:(CGRect)frame;

    @end

    #import "SDmoreCircle.h"

    @implementation SDmoreCircle

    +(instancetype)ViewWithCircle:(CGRect)rect

    {

        return [[self alloc]initWithFrame:rect];

    }

    -(instancetype)initWithFrame:(CGRect)frame

    {

        return [super initWithFrame:frame];

    }

    -(void)creatCircle:(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()%255/256.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1.0].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) {

            [layer setTransform:CATransform3DScale(layer.transform, 1.1, 1.1, 1.0)];

    //        其实说的就是_cmd在Objective-C的方法中表示当前方法的selector,正如同self表示当前方法调用的对象实例一样。

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

        }

        else

        {

            [layer removeFromSuperlayer];

        }

    }

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

    {

        [self creatCircle:touches];

    }

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

    {

        [self creatCircle:touches];

    }

    @end

  • 相关阅读:
    高并发系统如何设计
    PHP的垃圾回收机制(开启垃圾回收机制后的优缺点是什么)
    移动端网站如何开发(电脑端网站到手机端网站我们需要在html代码中添加哪个meta标签)
    家庭洗车APP --- Androidclient开展 之 网络框架包介绍(一)
    一天JavaScript示例-判定web页面的区域
    左右margin top问题百分比值
    Ubuntu14.04设备JDK
    三层架构,四大天王——删
    MEMO:UIButton 中的图片和标题 左对齐
    HDU 3874 离线段树
  • 原文地址:https://www.cnblogs.com/tianlianghong/p/5380501.html
Copyright © 2011-2022 走看看