p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px "PingFang SC"; color: #1d9421 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px }
p.p4 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421 }
p.p5 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3d1d81 }
span.s1 { font: 18.0px Menlo }
span.s2 { }
span.s3 { color: #c32275 }
span.s4 { color: #000000 }
span.s5 { font: 18.0px "PingFang SC" }
span.s6 { color: #6122ae }
span.s7 { color: #3d1d81 }
span.s8 { font: 18.0px Menlo; color: #000000 }
span.s9 { color: #703daa }
span.s10 { color: #0435ff }
span.s11 { color: #539aa4 }
span.s12 { color: #294c50 }
span.s13 { color: #78492a }

//CADisplayLink  和屏幕刷新频率相同

//开始下雪

- (void) beginShow{

//启动定时器,使得一直调用setNeedsDisplay从而调用- (void) drawRect:(CGRect )rect

//不得手动调用- (void) drawRect:(CGRect )rect

CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(setNeedsDisplay)];

//让定时器循环调用

[link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

}

- (void) drawRect:(CGRect)rect {

//控制雪花最多的个数

//    if (self.subviews.count >250) {

//        return;

//    }

if (self.subviews.count >20) {

return;

}

//雪花的宽度

int width = arc4random() % 5;

while (width < 2) {

width = arc4random() % 5;

}

//雪花的速度

int speed = arc4random() % 10;

while (speed < 5) {

speed = arc4random() % 10;

}

//雪花起点y

int startY = - (arc4random() % 100);

//雪花起点x

int startX = arc4random() % (int) [UIScreen mainScreen].bounds.size.width;

//雪花终点x

int endX = arc4random() % (int) [UIScreen mainScreen].bounds.size.width;

//int endX = arc4random() % (int)_bgView.height;

//int endX = arc4random() % (int)(_bgView.height - 71*GOP_HeightR);//同

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.snowImgName]];

imageView.frame = CGRectMake(startX, startY, width, width);

[self addSubview:imageView];

//设置动画

[UIView animateWithDuration:speed animations:^{

//设置雪花最终的frame

//        imageView.frame = CGRectMake(endX, [UIScreen mainScreen].bounds.size.height, width, width);

//雪花最终下落的高度为_bgView的高度减去71*GOP_HeightR的高度

imageView.frame = CGRectMake(endX, _bgView.height-71*GOP_HeightR, width, width);

//设置雪花的旋转

imageView.transform = CGAffineTransformRotate(imageView.transform, M_PI);

//设置雪花透明度,使得雪花快落地的时候就像快消失的一样

//imageView.alpha = 0.3;

} completion:^(BOOL finished) {

[imageView removeFromSuperview];

}];

}

雪花降落CADisplayLink的更多相关文章

  1. 雪花降落CAEmitterLayer粒子效果

    CAEmitterLayer 实现雪花效果   首先需要导入#import <QuartzCore/QuartzCore.h>   /**在iOS 5中,苹果引入了一个新的CALayer子 ...

  2. jq制作圣诞主题页面

    今天制作的是有飘雪效果的圣诞主题页面,个人灰常喜欢. 首先还是放张效果图: 当看到这这页面的时候我们要注意四点: 1.图片的轮播 2.文字的滚动效果 3.音乐播放 4.飘雪效果 那我们就一点一点来完成 ...

  3. 梦殇 chapter three

    chapter three 悲伤有N个层面.对于生命是孤独的底色,对于时间是流动的伤感,对于浪漫是起伏的变奏,对于善和怜悯是终生的慨叹…… 出去和舍友买完东西,刚回到宿舍,舍友就说,刚才有人给你打电话 ...

  4. AJ学IOS(33)UI之Quartz2D雪花飘落效果刷帧

    AJ分享,必须精品 效果: 可以加入随机数实现真的飘落效果哦. 代码: -(id)initWithCoder:(NSCoder *)aDecoder { //请注意这里一定要先初始化父类的构造方法 i ...

  5. IOS第16天(5,Quartz2D雪花)

    *** #import "HMView.h" @interface HMView() { int count; } @property (nonatomic, assign) CG ...

  6. iOS定时器-- NSTimer 和CADisplaylink

    iOS定时器-- NSTimer 和CADisplaylink 一.iOS中有两种不同的定时器: 1.  NSTimer(时间间隔可以任意设定,最小0.1ms)// If seconds is les ...

  7. iOS开发Quartz2D之 七:雪花效果

    #import "VCView.h" @implementation VCView -(void)awakeFromNib { //[NSTimer scheduledTimerW ...

  8. Objective-C三种定时器CADisplayLink / NSTimer / GCD的使用

    OC中的三种定时器:CADisplayLink.NSTimer.GCD 我们先来看看CADiskplayLink, 点进头文件里面看看, 用注释来说明下 @interface CADisplayLin ...

  9. CADisplayLink 及定时器的使用

    第一种: 用CADisplayLink可以实现不停重绘. 例子:   CADisplayLink* gameTimer; gameTimer = [CADisplayLink displayLinkW ...

随机推荐

  1. Could not execute auto check for display colors using command /usr/bin/xdpyinfo.(

    Steps to resolve this issue: 1) login into root user( su -l root) 2) execute this command : xhost +S ...

  2. RabbitMQ小白菜学习之在window下的安装配置

    RabbitMQ安装 首先需要下载RabbitMQ的平台环境Erlang OTP平台和RabbitMQ Server(windows版): OTP 19.1 Windows 64-bit Binary ...

  3. Hadoop权威指南:FSDataInputStream对象

    Hadoop权威指南:FSDataInputStream对象 FileSystem对象中的open()方法返回的是FSDataInputStream对象, 而不是标准的java.io类对象,这个类是继 ...

  4. JTable 的使用

    JTable是Swing编程中的一种控件. 一.创建表格控件的各种方式:1) 调用无参构造函数. JTable table = new JTable(); 2) 以表头和表数据创建表格. Object ...

  5. 使用Navicat Premium 链接本地数据库的方法

    在工作中,为了更方便的使用数据库,不免会用到Navicat Premium: 于是在重新安装电脑系统之后,原本想在其中链接一下本地数据库, 只是在链接途中要写的密码一项却不晓得应该写什么,想了很久密码 ...

  6. Python学习--17 访问数据库

    实际开发中,我们会经常用到数据库. Python里对数据库的操作API都很统一. SQLite SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以 ...

  7. java_JDBC(3)

    Batch和Fetch两个特性非常重要.Batch相当于JDBC的写缓冲,Fetch相当于读缓冲 如果把JDBC类比为JAVA IO的话,不使用Fetch和Batch相当于直接使用FileInputS ...

  8. css3 3d初入门(一)

    css3 3D.html div.oembedall-githubrepos { border: 1px solid #DDD; list-style-type: none; margin: 0 0 ...

  9. io的四个分类

    1.首先是字节操作:InputStream和OutputStream 2.字符操作:Reader和Writer 3.磁盘操作:File 4.网络操作:scoket(不在java.io包)

  10. TCP报文段的首部格式

    首部20个字节的的固定部分,40个字节的可选部分 (1)源端口和目的端口 (2)序号(是字节流的编号,0-2^32-1),如果超过了mod2^32 (3)确认号:目的主机希望源主机收到的下一个字节序号 ...