2016-1-8 Quartz框架的学习,多个气球上升的小动画
//
// BallonView.m
// 气球上升的动画
//
// Created by Mac on 16/1/8.
// Copyright © 2016年 Mac. All rights reserved.
// #import "BallonView.h"
@interface BallonView() @property (nonatomic, assign) NSString *postions;
@property (nonatomic, strong) CADisplayLink *link;
@property (nonatomic, strong) NSMutableArray *locations;
@property (nonatomic, strong) NSMutableArray *ballons; @end
@implementation BallonView
//懒加载 存储位置
- (NSMutableArray *)locations
{
if (!_locations) {
_locations = [NSMutableArray array];
}
return _locations;
}
- (NSMutableArray *)ballons
{
if (!_ballons) {
_ballons = [NSMutableArray array];
NSInteger count = ;
UIImage *ballonImage =[UIImage imageNamed:@"sandyBalloon"];
for (int i = ; i < count; i ++) {
CGFloat left = ;
CGPoint location = CGPointMake(left*(i+), self.frame.size.height - );
// [ballonImage drawAtPoint:location];
[self.locations addObject:[NSValue valueWithCGPoint:location]];
[_ballons addObject:ballonImage];
}
}
return _ballons;
} // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
NSInteger ballonsOfCount = self.ballons.count;
for (int i = ; i < ballonsOfCount; i ++) {
// 获取气球的位置
CGPoint postion = [self.locations[i] CGPointValue];
postion.y -= arc4random_uniform() * 0.7;
if (postion.y == ) {
postion.y = rect.size.height;
} [self.locations replaceObjectAtIndex:i withObject:[NSValue valueWithCGPoint:postion]];
[self.ballons[i] drawAtPoint:postion];
}
NSLog(@"%s",__func__); } // ------------------------------------------------------------------------------------------------------------------
// Drawing code - (instancetype)init
{
if (self = [super init]) {
[self addAnimition];
}
return self;
}
- (void) addAnimition
{
// [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(setNeedsDisplay) userInfo:nil repeats:YES];
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(setNeedsDisplay)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
self.link = link;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.link invalidate];
} @end

2016-1-8 Quartz框架的学习,多个气球上升的小动画的更多相关文章
- 2016-1-9 Quartz框架的学习,写字板demo
一:自定义view .h文件中代码如下 #import <UIKit/UIKit.h> @interface ZLpaintView : UIView @property(nonatomi ...
- 2016-1-9 Quartz框架的学习,剪裁图片并设置边框
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- pythonweb框架Flask学习笔记02-一个简单的小程序
#-*- coding:utf-8 -*- #导入了Flask类 这个类的实例将会是我们的WSGI应用程序 from flask import Flask #创建一个Flask类的实例 第一个参数是应 ...
- Quartz框架学习(1)—核心层次结构
Quartz框架学习 Quartz(任务调度)框架的核心组件: job:任务.即任务调度行为中所要调度的对象. trigger:触发器.是什么促使了一个任务的调度?当然是时间.这也算事件驱动类型程序. ...
- Quartz框架(第一版)
任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...
- Quartz框架
Quartz框架 Quartz 是个开源的作业调度框架,为在 Java 应用程序中进行作业调度提供了简单却强大的机制.Quartz 允许开发人员根据时间间隔(或天)来调度作业.它实现了作业和触发器的多 ...
- spring整合Quartz框架过程,大家可以参考下
这篇文章详细介绍了spring集成quartz框架流程,通过示例代码进行了详细说明,对学习或任务有参考学习价值,并可供需要的朋友参考. 1.quartz框架简介(m.0831jl.com) quart ...
- DBFlow框架的学习笔记之入门
什么是DBFlow? dbflow是一款android高性的ORM数据库.可以使用在进行项目中有关数据库的操作.github下载源码 1.环境配置 先导入 apt plugin库到你的classpat ...
- 【淘淘】Spring整合Quartz框架
我在外面工作实习的时候,我们做的项目是一个日报子系统,也就是定时定点为公司生成一些报表数据还有一些数据反馈.这时候我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.当时,我做 ...
随机推荐
- VS2012给同一个解决方案添加多个项目
1.选择文件->添加->新建项目或现有项目 2.接下来在解决方案资源管理器中我们会发现解决方ConsoleApplication1中有两个项目,这里一个是类库项目ClassLibrary1 ...
- canvas实现绘画
html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- webBrowser1执行函数
IHTMLWindow2 Win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;string s = "alert('x');& ...
- WordPress怎么在页面上添加目录
要实现的如下功能,在页面上添加一个文章目录: 步骤: 1)在wordpress中,在Posts----Categories中建立目录, 2) 3)add new post,指定post所属的cat ...
- Java集合——List接口
1.定义 List是Collection的子接口,元素有序并且可以重复,表示线性表. 2.方法 add(int index,Object e):在指定索引(和数组下标类似,为0,1,2....)放入元 ...
- uva 1629
1629 - Cake slicing Time limit: 3.000 seconds A rectangular cake with a grid of m * n <tex2html_v ...
- SQL语句技巧(上个样式太差了)
以下并非本人整理,但是看后感觉相当不错,特此分享. 1.应用程序中,保证在实现功能的基础上,尽量减少对数据库的访问次数:通过搜索参数,尽量减少对表的访问行数,最小化结果集,从而减轻网络负担:能够分 ...
- chrome密码管理
chrome://settings/passwords ------------------------------- [系统盘]:\Documents and Settings\[用户名]\Loca ...
- Steam和Byte[]之间进行输换
一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; Image img = Image.FromStream ...
- MySQL 查看表结构
mysql查看表结构命令,如下: desc 表名; show columns from 表名; describe 表名; show create table 表名; use information_s ...