心形加载的view

效果:

素材图片:

源码:

StarView.h 与 StarView.m

//
// StarView.h
// Star
//
// Created by XianMingYou on 15/3/13.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import <UIKit/UIKit.h> @interface StarView : UIView @property (nonatomic, strong) UIColor *backgroundViewColor;
@property (nonatomic, strong) UIColor *animationViewColor;
@property (nonatomic, assign) NSTimeInterval animationDuration; + (instancetype)createWithFrame:(CGRect)frame
backgroundViewColor:(UIColor *)bgColor
animationViewColor:(UIColor *)anColor; - (void)percent:(CGFloat)percent animated:(BOOL)animated; @end
//
// StarView.m
// Star
//
// Created by XianMingYou on 15/3/13.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "StarView.h"
#import "UIView+SetRect.h" @interface StarView () @property (nonatomic, strong) UIImageView *imageView; // 图片
@property (nonatomic, strong) UIView *backgroundView; // 背景色View
@property (nonatomic, strong) UIView *animationView; // 做动画的View @property (nonatomic) CGFloat height;
@property (nonatomic) CGFloat width; @end @implementation StarView - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.layer.masksToBounds = YES;
self.height = frame.size.height;
self.width = frame.size.width; [self addSubview:self.backgroundView]; [self addSubview:self.animationView]; [self initImageView];
}
return self;
} - (void)initImageView {
self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
self.imageView.image = [UIImage imageNamed:@"star"]; [self addSubview:self.imageView];
} - (void)percent:(CGFloat)percent animated:(BOOL)animated {
// 过滤percent
if (percent <= ) {
percent = ;
} else if (percent >= ) {
percent = ;
} if (animated == NO) {
CGFloat positionY = self.height * ( - percent);
_animationView.y = positionY;
} else {
CGFloat positionY = self.height * ( - percent);
[UIView animateWithDuration:(self.animationDuration <= ? 0.5 : self.animationDuration)
animations:^{
_animationView.y = positionY;
}];
}
} + (instancetype)createWithFrame:(CGRect)frame
backgroundViewColor:(UIColor *)bgColor
animationViewColor:(UIColor *)anColor {
StarView *star = [[StarView alloc] initWithFrame:frame];
star.backgroundViewColor = bgColor;
star.animationViewColor = anColor; return star;
} @synthesize backgroundView = _backgroundView;
- (UIView *)backgroundView {
if (_backgroundView == nil) {
_backgroundView = [[UIView alloc] initWithFrame:self.bounds];
} return _backgroundView;
} @synthesize animationView = _animationView;
- (UIView *)animationView {
if (_animationView == nil) {
_animationView = [[UIView alloc] initWithFrame:CGRectMake(, self.height, self.width, self.height)];
} return _animationView;
} @synthesize backgroundViewColor = _backgroundViewColor;
- (UIColor *)backgroundViewColor {
return _backgroundViewColor;
}
- (void)setBackgroundViewColor:(UIColor *)backgroundViewColor {
_backgroundViewColor = backgroundViewColor;
_backgroundView.backgroundColor = backgroundViewColor;
} @synthesize animationViewColor = _animationViewColor;
- (UIColor *)animationViewColor {
return _animationViewColor;
}
- (void)setAnimationViewColor:(UIColor *)animationViewColor {
_animationViewColor = animationViewColor;
_animationView.backgroundColor = animationViewColor;
}
@end

辅助文件 UIView+SetRect.h 与 UIView+SetRect.m

//
// UIView+SetRect.h
// TestPch
//
// Created by YouXianMing on 14-12-26.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface UIView (SetRect) // Frame
@property (nonatomic) CGPoint viewOrigin;
@property (nonatomic) CGSize viewSize; // Frame Origin
@property (nonatomic) CGFloat x;
@property (nonatomic) CGFloat y; // Frame Size
@property (nonatomic) CGFloat width;
@property (nonatomic) CGFloat height; // Frame Borders
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat bottom;
@property (nonatomic) CGFloat right; // Center Point
#if !IS_IOS_DEVICE
@property (nonatomic) CGPoint center;
#endif
@property (nonatomic) CGFloat centerX;
@property (nonatomic) CGFloat centerY; // Middle Point
@property (nonatomic, readonly) CGPoint middlePoint;
@property (nonatomic, readonly) CGFloat middleX;
@property (nonatomic, readonly) CGFloat middleY;
@property (nonatomic, assign) CGFloat cornerRadius ;
@property (nonatomic ,assign) BOOL round ;
@end
//
// UIView+SetRect.m
// TestPch
//
// Created by YouXianMing on 14-12-26.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "UIView+SetRect.h" @implementation UIView (SetRect) #pragma mark Frame - (CGPoint)viewOrigin
{
return self.frame.origin;
} - (void)setViewOrigin:(CGPoint)newOrigin
{
CGRect newFrame = self.frame;
newFrame.origin = newOrigin;
self.frame = newFrame;
} - (CGSize)viewSize
{
return self.frame.size;
} - (void)setViewSize:(CGSize)newSize
{
CGRect newFrame = self.frame;
newFrame.size = newSize;
self.frame = newFrame;
} #pragma mark Frame Origin - (CGFloat)x
{
return self.frame.origin.x;
} - (void)setX:(CGFloat)newX
{
CGRect newFrame = self.frame;
newFrame.origin.x = newX;
self.frame = newFrame;
} - (CGFloat)y
{
return self.frame.origin.y;
} - (void)setY:(CGFloat)newY
{
CGRect newFrame = self.frame;
newFrame.origin.y = newY;
self.frame = newFrame;
} #pragma mark Frame Size - (CGFloat)height
{
return self.frame.size.height;
} - (void)setHeight:(CGFloat)newHeight
{
CGRect newFrame = self.frame;
newFrame.size.height = newHeight;
self.frame = newFrame;
} - (CGFloat)width
{
return self.frame.size.width;
} - (void)setWidth:(CGFloat)newWidth
{
CGRect newFrame = self.frame;
newFrame.size.width = newWidth;
self.frame = newFrame;
} #pragma mark Frame Borders - (CGFloat)left
{
return self.x;
} - (void)setLeft:(CGFloat)left
{
self.x = left;
} - (CGFloat)right
{
return self.frame.origin.x + self.frame.size.width;
} - (void)setRight:(CGFloat)right
{
self.x = right - self.width;
} - (CGFloat)top
{
return self.y;
} - (void)setTop:(CGFloat)top
{
self.y = top;
} - (CGFloat)bottom
{
return self.frame.origin.y + self.frame.size.height;
} - (void)setBottom:(CGFloat)bottom
{
self.y = bottom - self.height;
} #pragma mark Center Point #if !IS_IOS_DEVICE
- (CGPoint)center
{
return CGPointMake(self.left + self.middleX, self.top + self.middleY);
} - (void)setCenter:(CGPoint)newCenter
{
self.left = newCenter.x - self.middleX;
self.top = newCenter.y - self.middleY;
}
#endif - (CGFloat)centerX
{
return self.center.x;
} - (void)setCenterX:(CGFloat)newCenterX
{
self.center = CGPointMake(newCenterX, self.center.y);
} - (CGFloat)centerY
{
return self.center.y;
} - (void)setCenterY:(CGFloat)newCenterY
{
self.center = CGPointMake(self.center.x, newCenterY);
} #pragma mark Middle Point - (CGPoint)middlePoint
{
return CGPointMake(self.middleX, self.middleY);
} - (CGFloat)middleX
{
return self.width / ;
} - (CGFloat)middleY
{
return self.height / ;
} - (void)setCornerRadius:(CGFloat)cornerRadius
{
self.layer.masksToBounds = YES ;
self.layer.cornerRadius = cornerRadius ;
} - (void)setRound:(BOOL)round
{
[self setCornerRadius:self.height/];
} - (CGFloat)cornerRadius
{
return self.layer.cornerRadius ;
} - (BOOL)round
{
return NO ;
} @end

使用时候的源码:

//
// ViewController.m
// Star
//
// Created by XianMingYou on 15/3/13.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ViewController.h"
#import "StarView.h" @interface ViewController () @property (nonatomic, strong) StarView *star;
@property (nonatomic, strong) NSTimer *timer; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.star = [StarView createWithFrame:CGRectMake(, , , )
backgroundViewColor:[[UIColor redColor] colorWithAlphaComponent:0.05f]
animationViewColor:[[UIColor redColor] colorWithAlphaComponent:0.5f]];
self.star.animationDuration = .f;
self.star.center = self.view.center;
[self.view addSubview:self.star]; self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5f
target:self
selector:@selector(timerEvent:)
userInfo:nil
repeats:YES];
} - (void)timerEvent:(id)sender {
CGFloat percent = arc4random() % / .f;
[self.star percent:percent animated:YES];
} @end

[控件] 心形加载的view的更多相关文章

  1. jQuery EasyUI动态添加控件或者ajax加载页面后不能自动渲染问题的解决方法

    博客分类: jquery-easyui jQueryAjax框架HTML  现象: AJAX返回的html无法做到自动渲染为EasyUI的样式.比如:class="easyui-layout ...

  2. Winform DevExpress控件库(二) 使用SplashScreenManager控件定制程序加载页面

    SplashScreenManager控件:主要作用是显示在进行耗时操作时的等待界面: 位于 工具箱 -> Navigation & Layout(导航栏与布局类控件) 目录下: 在工具 ...

  3. 使用SplashScreenManager控件定制程序加载页面

    需要devexpress版本在12.0及以上才支持 https://www.cnblogs.com/wuhuacong/p/6112461.html 在DevExpress程序中使用SplashScr ...

  4. zTree 树形控件 ajax动态加载数据

    很久没搞过树形控件了 , 再次接触看官网文档有点没懂,于是在网上找了个代码copy上,但数据是写死的,就想这在用ajax异步取出数据替换,下面是js代码 <SCRIPT type="t ...

  5. 扩展easyUI tab控件,添加加载遮罩效果

    项目里要用HighChart显示图表,如果返回的数量量太多,生成图表是一个很耗时的过程.tab控件又没有显示遮罩的设置(至少本菜是没有找到), Google了一下,根据另一个兄台写的方法,拿来改造了一 ...

  6. Webbrowser控件判断网页加载完毕的简单方法 (转)

    摘自:http://blog.csdn.net/cometnet/article/details/5261192 一般情况下,当ReadyState属性变成READYSTATE_COMPLETE时,W ...

  7. C#自定义控件、用户控件、动态加载菜单按钮

    一.效果图,动态加载5个菜单按钮: 二.实现方法 1.创建用户控件 2.在用户控件拖入toolStrip 3.进入用户控件的Lood事件,这里自动添加5个选  ToolStripMenuItem,后期 ...

  8. asp.net读取用户控件,自定义加载用户控件

    1.自定义加载用户控件 ceshi.aspx页面 <html> <body> <div id="divControls" runat="se ...

  9. 02、获取 WebView 控件中,加载的 HTML 网页内容

    在开发 app 的时候,WebView 是经常使用的控件.而且有时需要向 WebView 中的 html 内容 注入额外的 js 进行操作.这里记录一下在当前 WebView 控件中,获取 html ...

随机推荐

  1. C++中对象模型

    C++面向对象语言一大难点是继承,但又是不得不掌握的.简单的继承是很容易理解的,但是当涉及到多继承,设计到虚函数的继承,特别是涉及到虚继承时,问题就会变得复杂.下面的内容来自参考资料中的三篇文章.C+ ...

  2. GDI+中发生一般性错误的解决办法(转)

    今天在开发.net引用程序中,需要System.Drawing.Image.Save 创建图片,debug的时候程序一切正常,可是发布到IIS后缺提示出现"GDI+中发生一般性错误" ...

  3. SpringBoot源码分析之SpringBoot的启动过程

    SpringBoot源码分析之SpringBoot的启动过程 发表于 2017-04-30   |   分类于 springboot  |   0 Comments  |   阅读次数 SpringB ...

  4. unity 判断平台(安卓,iOS还是编辑器)

    两种方式 --------------- C预处理器编译判断 --------------- #if UNITY_IOS // ... iOS项目才会编译 #elif UNITY_ANDROID // ...

  5. javascript正则表达式获取控制

    正则表达式的元字符是包含特殊含义的字符,他们有一些特殊的功能,可以控制匹配模式的方式,反斜杠后的元字符将失去其特殊含义 单个字符 元字符 匹配情况 . 匹配除换行符外的任意字符 [a-z0-9] 匹配 ...

  6. 新增的input

    原有的input类型: input标签原有的type类型: text(普通文本框,默认字) button(普通按钮) password(密码框)   submit(提交按钮) radio(单选框) r ...

  7. C# 使用/配置Log4Net

    1.首先在项目中添加Nuget程序包... 2.然后在NuGet窗体中搜索Log4Net,然后点击安装<安装过程可能会持续几分钟,请耐心等待> 3.在项目中添加一个Config文件,如已有 ...

  8. 关于ajaxFileUpload只能上传一次的解决

    今天用ajaxFileUpload做了一个上传文件到服务器的功能. 出现问题:先上传了一次,后来发现读取完成以后,再上传的时候前台调试file和自动义参数都传进,但后台获取的仍然是上一次上传时的相关参 ...

  9. 二进制GCD算法 减少%的时间消耗

    /* 二进制求最大公约数.由于传统的GCD,使用了%,在计算机运行过程中要花费大量的时间,所以,采取二进制的求法,来减少时间的消耗. 算法: 当a,b都是偶数时: gcd(a,b)=2*gcd(a/2 ...

  10. importnew:Map大家族的那点事儿

    Map大家族的那点事儿(1) :Map Map大家族的那点事儿(2) :AbstractMap Map大家族的那点事儿(3) :TreeMap Map大家族的那点事儿(4) :HashMap Map ...