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

本次主要讲交互

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)];

}

最新文章

  1. 创建dialog
  2. Python4周 入职培训的过程
  3. selenium打开带有扩展的chrome
  4. lua学习笔记之-语言基础
  5. 查看ip地址信息和配置临时ip
  6. 获取iOS应用的版本号和app名称
  7. nginx负载均衡(一)
  8. linux生成公钥私钥并上传到服务器上实现免密登陆
  9. 关于windows下的makefile学习
  10. bzoj3545 Peaks
  11. MAC上mongodb连接不上
  12. eclipse格式化代码样式
  13. jQuery animate() 改变颜色
  14. Kettle变量和自己定义java代码的实例应用
  15. N-Gram的数据结构
  16. HDU 4115 Eliminate the Conflict(2-SAT)(2011 Asia ChengDu Regional Contest)
  17. Navicat断网时连不上数据库
  18. Spark on Yarn——spark1.5.1集群配置
  19. cocos2d-x 打包成so文件之后,假设出现错误,能够使用ndk-stack来查看里面的异常
  20. 【BZOJ2440】完全平方数(莫比乌斯函数,容斥原理)

热门文章

  1. Bellman-Ford 单源最短路径算法
  2. 我认为JS还可以改进的点
  3. 疯狂的JSONP
  4. 压缩javascript文件方法
  5. ABP源码分析三十四:ABP.Web.Mvc
  6. maven archetype二三事
  7. 遍历dynamic的方式
  8. Memcached和Redis比较
  9. 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)
  10. B树和B+树的区别