心形加载的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. go语言的unsafe包(转)

    The unsafe Package in Golang Golang的unsafe包是一个很特殊的包. 为什么这样说呢? 本文将详细解释. 来自go语言官方文档的警告 unsafe包的文档是这么说的 ...

  2. java 之 异常处理小结

    1 :分类 检查异常(checked,受检) 运行异常(unchecked) 2:捕获异常 try/catch    try/catch/finally   try/finally try{ //受保 ...

  3. 【BI】资料收集

    从无到有--什么是BI 什么是BI(Business Intelligence) - @我爱菊花 - 博客园 http://www.cnblogs.com/jiesin/archive/2008/06 ...

  4. SQL查询几种的区别。

    最近看了几篇SQL查询的文章做一下总结哦,大概简记如下: SQL查询的实质是,是指从数据库中取得数据的子集,可以先取列子集,然后再取符合条件的行子集. 1.单表查询: SELECT [Name] ,[ ...

  5. Linux root用户不能通过SSH连接的问题

    http://jingyan.baidu.com/article/fd8044fad48fc95031137a85.html 最近在虚拟机安装Ubuntu之后,通过普通ssh远程连接的时候明明输入了正 ...

  6. 我在项目中运用 IOC(依赖注入)--实战篇

    上一篇<我在项目中运用 IOC(依赖注入)--入门篇>只是简单的使用 IOC.实际项目使用 IOC 的情景复杂多了,比如说,构造函数有多个参数,有多个类继承同一个接口... Unity都有 ...

  7. fzu 2132 LQX的作业

    Problem 2132 LQX的作业 Accept: 67    Submit: 150Time Limit: 1000 mSec    Memory Limit : 32768 KB Proble ...

  8. Java的工厂模式(三)

    除了一般的工厂模式之外,还有抽象工厂模式,抽象工厂模式更强调产品族的概念,一个具体工厂生产出来的系列商品都是一个产品族的. 假设我们有两个具体工厂,分别是袋装水果工厂和罐装水果工厂,它们都能生产苹果和 ...

  9. 微软正式开源Blazor,将.NET带回到浏览器

    微软 ASP.NET 团队近日正式开源了Blazor,这是一个Web UI框架,可通过WebAssembly在任意浏览器中运行 .Net. Blazor旨在简化快速的单页面 .Net 浏览器应用的构建 ...

  10. MarkDownPad 专业汉化破解

     解压Pa_ttrar 运行Pa_ttrar.exe    点击下边第一个按钮“patch”——>弹出窗选择“YES”  选择“YES”后会选择一个文件,找到“C:\Users\用户名\AppD ...