zoukankan      html  css  js  c++  java
  • 记录一次Quartz2D学习(七)

    (六)内主要讲述了图片的裁剪

    本次主要讲交互

    7.交互

      7.1  通过外部刷新内部的显示效果

        初始化的时候设定好初始值,调用setNeedsDisplay方法来重新绘制

    - (instancetype)init

    {

        self = [super init];

        if (self) {

            self.backgroundColor = [UIColor whiteColor];

        }

        return self;

    }

    - (instancetype)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            NSLog(@"initWithFrame");

            self.radius = 1 ;

            self.backgroundColor = [UIColor whiteColor];

        }

        return self;

    }

     

    -(void)setRadius:(float)radius{

        _radius = radius*100;

        [self setNeedsDisplay];

    }

     

    - (void)drawRect:(CGRect)rect {

        NSLog(@"drawRect:%f",self.radius);

        CGContextRef  ctx = UIGraphicsGetCurrentContext();

        [[UIColor grayColor] set];

        CGContextAddArc(ctx, 150, 150, self.radius, 0, M_PI*2, 0);

        

        CGContextFillPath(ctx);

    }

     

     

     

     

     

     

    7.2使用runLoop进行逐帧播放的动画 

     

    - (instancetype)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            self.backgroundColor = [UIColor whiteColor];

            self.img_y=0;

    //初始化时间管理器

            CADisplayLink *  displayer =[CADisplayLink displayLinkWithTarget:self selector:@selector(upDateImage)];

    //添加时间管理器到runLoop

            [displayer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];

        }

        return self;

    }

    -(void)upDateImage{

        [self setNeedsDisplay];

    }

    - (void)drawRect:(CGRect)rect {

    //位移量

        self.img_y +=5;

    //防止越界

        if (self.img_y > [UIScreen mainScreen].bounds.size.height) {

            self.img_y = 0;

        }

    //可有可无

        CGContextRef  ctx = UIGraphicsGetCurrentContext();

    //图片加载

        UIImage * img =[UIImage imageNamed:@"图标-首页"];

    //图片绘制到对应点

        [img drawAtPoint:CGPointMake(0, self.img_y)];

    }

     

     

     

     

     

     

     

     

  • 相关阅读:
    Android 如何自定义EditText 下划线?
    一步一步理解 Java 企业级应用的可扩展性
    客户案例—北京优络时代科技有限公司
    11个显著提升 ASP.NET 应用程序性能的技巧——第1部分
    如何用 React Native 创建一个iOS APP?(二)
    如何与 DevOps 为伍?
    通过 DevOps 整合开发和应用安全管道
    性能为王:选择模拟监控的10大理由!
    模拟监控和真实用户体验监测,选哪个?
    PHP 之 Laravel 框架安装及相关开源软件
  • 原文地址:https://www.cnblogs.com/thxios/p/5145518.html
Copyright © 2011-2022 走看看