心形加载的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. LDAP落地实战(二):SVN集成OpenLDAP认证

    上一篇文章我们介绍了LDAP的部署以及管理维护,那么如何接入LDAP实现账号统一认证呢?这篇文章将带你完成svn的接入验证 subversion集成OpenLDAP认证 系统环境:debian8.4 ...

  2. 哪个先执行:@PostConstruct和@Bean的initMethod?

    结论: /** * step1:执行构造函数 * step2:执行使用@PostConstruct注解修饰的方法[如果有多个,则执行顺序不确定] * step3:执行@Bean注解中initMetho ...

  3. c# winform项目用到的部分知识点总结

    项目用到的知识点总结,欢迎大家吐槽: /// <summary> /// 转换非yyyy-MM-dd的字符串为DateTime类型 /// </summary> public ...

  4. sql语句中出现笛卡尔乘积 SQL查询入门篇

    2014-12-29  凡尘工作室   阅 34985  转 95 本篇文章中,主要说明SQL中的各种连接以及使用范围,以及更进一步的解释关系代数法和关系演算法对在同一条查询的不同思路. 多表连接简介 ...

  5. c#基础学习(0627)之类型转换、算数运算符++、--

    类型转换 我们要求等号两边参与运算的操作数的类型必须一致,如果不一致,满足下列条件会发生自动类型转换,或者称之为隐式类型转换 例如:int和double兼容(都是数字类型) 目标类型大于源类型 例如: ...

  6. Mvc Moq HttpContext

    1: public class MockMvcHttpContext 2: { 3: public Moq.Mock<System.Web.HttpContextBase> Context ...

  7. [日常] CentOS安装最新版redis设置远程连接密码

    wget http://download.redis.io/releases/redis-4.0.8.tar.gztar -zxvf redis-4.0.8.tar.gzmake完成后就会放在了src ...

  8. Java的简单书写格式

    在一个java源代码中只能出现一个public类,而且必须跟文件名相同 在源代码的全局域类中只有 public 和 default 两种可见度 全局域不能写代码,只能定义类 成员类的构造方法和类的可见 ...

  9. node.js和JavaScript的关系

    node.js是一个基于 Chrome V8 引擎的 JavaScript 运行时环境. 一.类比JavaScript和java JavaScript java V8 JVM node.js JRE ...

  10. HDU2102(KB2-I)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...