动态实现3D标签,

主要代码:

//
// XLMatrix.h
// XLSphereView
//
// Created by 史晶晶 on 16/4/4.
// Copyright © 2016年 xiaolong. All rights reserved.
// #ifndef XLMatrix_h
#define XLMatrix_h #import "XLPoint.h" struct XLMatrix {
NSInteger column;
NSInteger row;
CGFloat matrix[][];
}; typedef struct XLMatrix XLMatrix; static XLMatrix XLMatrixMake(NSInteger column, NSInteger row) {
XLMatrix matrix;
matrix.column = column;
matrix.row = row;
for(NSInteger i = ; i < column; i++){
for(NSInteger j = ; j < row; j++){
matrix.matrix[i][j] = ;
}
} return matrix;
} static XLMatrix XLMatrixMakeFromArray(NSInteger column, NSInteger row, CGFloat *data) {
XLMatrix matrix = XLMatrixMake(column, row);
for (int i = ; i < column; i ++) {
CGFloat *t = data + (i * row);
for (int j = ; j < row; j++) {
matrix.matrix[i][j] = *(t + j);
}
}
return matrix;
} static XLMatrix XLMatrixMutiply(XLMatrix a, XLMatrix b) {
XLMatrix result = XLMatrixMake(a.column, b.row);
for(NSInteger i = ; i < a.column; i ++){
for(NSInteger j = ; j < b.row; j ++){
for(NSInteger k = ; k < a.row; k++){
result.matrix[i][j] += a.matrix[i][k] * b.matrix[k][j];
}
}
}
return result;
} static XLPoint XLPointMakeRotation(XLPoint point, XLPoint direction, CGFloat angle) {
// CGFloat temp1[4] = {direction.x, direction.y, direction.z, 1};
// XLMatrix directionM = XLMatrixMakeFromArray(1, 4, temp1);
if (angle == ) {
return point;
} CGFloat temp2[][] = {point.x, point.y, point.z, };
// XLMatrix pointM = XLMatrixMakeFromArray(1, 4, *temp2); XLMatrix result = XLMatrixMakeFromArray(, , *temp2); if (direction.z * direction.z + direction.y * direction.y != ) {
CGFloat cos1 = direction.z / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat sin1 = direction.y / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat t1[][] = {{, , , }, {, cos1, sin1, }, {, -sin1, cos1, }, {, , , }};
XLMatrix m1 = XLMatrixMakeFromArray(, , *t1);
result = XLMatrixMutiply(result, m1);
} if (direction.x * direction.x + direction.y * direction.y + direction.z * direction.z != ) {
CGFloat cos2 = sqrt(direction.y * direction.y + direction.z * direction.z) / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat sin2 = -direction.x / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat t2[][] = {{cos2, , -sin2, }, {, , , }, {sin2, , cos2, }, {, , , }};
XLMatrix m2 = XLMatrixMakeFromArray(, , *t2);
result = XLMatrixMutiply(result, m2);
} CGFloat cos3 = cos(angle);
CGFloat sin3 = sin(angle);
CGFloat t3[][] = {{cos3, sin3, , }, {-sin3, cos3, , }, {, , , }, {, , , }};
XLMatrix m3 = XLMatrixMakeFromArray(, , *t3);
result = XLMatrixMutiply(result, m3); if (direction.x * direction.x + direction.y * direction.y + direction.z * direction.z != ) {
CGFloat cos2 = sqrt(direction.y * direction.y + direction.z * direction.z) / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat sin2 = -direction.x / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat t2_[][] = {{cos2, , sin2, }, {, , , }, {-sin2, , cos2, }, {, , , }};
XLMatrix m2_ = XLMatrixMakeFromArray(, , *t2_);
result = XLMatrixMutiply(result, m2_);
} if (direction.z * direction.z + direction.y * direction.y != ) {
CGFloat cos1 = direction.z / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat sin1 = direction.y / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat t1_[][] = {{, , , }, {, cos1, -sin1, }, {, sin1, cos1, }, {, , , }};
XLMatrix m1_ = XLMatrixMakeFromArray(, , *t1_);
result = XLMatrixMutiply(result, m1_);
} XLPoint resultPoint = XLPointMake(result.matrix[][], result.matrix[][], result.matrix[][]); return resultPoint;
} #endif /* XLMatrix_h */
 //
// ViewController.m
// XLSphereView
//
// Created by 史晶晶 on 16/4/4.
// Copyright © 2016年 xiaolong. All rights reserved.
// #import "ViewController.h"
#import "XLSphereView.h" @interface ViewController () @property (nonatomic,strong) XLSphereView *sphereView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor];
CGFloat sphereViewW = self.view.frame.size.width - * ;
CGFloat sphereViewH = sphereViewW;
_sphereView = [[XLSphereView alloc] initWithFrame:CGRectMake(, , sphereViewW, sphereViewH)];
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:];
for (NSInteger i = ; i < ; i ++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:[NSString stringWithFormat:@"晶%ld", i] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize: 7.0];
btn.backgroundColor = [UIColor colorWithRed:arc4random_uniform()/. green:arc4random_uniform()/. blue:arc4random_uniform()/. alpha:.];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:.];
btn.frame = CGRectMake(, , , );
btn.layer.cornerRadius = ;
btn.clipsToBounds = YES;
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[array addObject:btn];
[_sphereView addSubview:btn];
}
[_sphereView setItems:array];
[self.view addSubview:_sphereView]; } - (void)buttonPressed:(UIButton *)btn
{
[_sphereView timerStop]; [UIView animateWithDuration:0.3 animations:^{
btn.transform = CGAffineTransformMakeScale(., .);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
btn.transform = CGAffineTransformMakeScale(., .);
} completion:^(BOOL finished) {
[_sphereView timerStart];
}];
}];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

demo截图

下载地址:

https://github.com/henusjj/Label-effect

3D标签的更多相关文章

  1. 设计3D标签

    java自带的Label太枯燥了,真是拿不出手啊. 所以,我们要设计3D标签!! 看看下面这张图 原理 看看这图,可以看到哈哈有三种颜色:白色.黑色和灰色 实现的时候并不像PS那样,按几个按钮就O了 ...

  2. css3实践之摩天轮式图片轮播+3D正方体+3D标签云(perspective、transform-style、perspective-origin)

    本文主要通过摩天轮式图片轮播的例子来讲解与css3 3D有关的一些属性. demo预览: 摩天轮式图片轮播(貌似没兼容360 最好用chrome) 3D正方体(chrome only) 3D标签云(c ...

  3. SP2010 3D标签云Web部分--很酷的效果,强烈推荐!!

    SP2010 3D标签云Web部分--很酷的效果.强烈推荐! ! 项目描述叙事         基于简单Flash的3D标签云Web部件.SP Server 2010使用. 建立在内置标签云Web部件 ...

  4. 解析3D标签云,其实很简单

    声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 最近开始用canvas搞3D了,搞得也是简单的东西,就是球体转圈.做出来后,突然想起以前看过的3D标签云,在以前觉得真心狂拽酷炫叼啊,当时 ...

  5. jquery 3D 标签云

    http://www.gbin1.com/technology/jquerynews/20111205tagcloudbyjquery/index.html 相关选项 zoom: 90 初始的缩放度  ...

  6. 【HMTL】3D标签球

    这是一个3D TAG 在网站展示中是个不错的东东,能让人眼前一亮,值得收藏. 这个是效果: 源码下载: 点 击 下 载

  7. 纯JS实现的3D标签云,不依赖不论什么第三方库,支持移动页面

    <span style="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html PUBLIC &q ...

  8. 3d标签云(JS版)

    http://www.miaov.com/miaov_demo/3dLable/miaov_demo.html http://www.lijian.net/p/windstagball/index.h ...

  9. 3D标签云

    一.圆的坐标表达式 for(var i = 0;i < len;i++){ degree = (2*(k+1)-1)/len - 1;a = Math.acos(degree);//这样取得弧度 ...

随机推荐

  1. k8s1.13.0二进制部署-ETCD集群(一)

    Kubernetes集群中主要存在两种类型的节点:master.minion节点. Minion节点为运行 Docker容器的节点,负责和节点上运行的 Docker 进行交互,并且提供了代理功能.Ma ...

  2. javaweb基础(23)_jsp自定义标签

    一.自定义标签的作用 自定义标签主要用于移除Jsp页面中的java代码. 二.自定义标签开发和使用 2.1.自定义标签开发步骤 1.编写一个实现Tag接口的Java类(标签处理器类) 1 packag ...

  3. 使用struts2实现文件上传与下载功能

    这个问题做了两天,在网上找了很多例子,但是还有一些功能没有实现,暂时先把代码贴出来,以后在做这方面的功能时在修改 文件上传: 一开始我在网上找到基于servlet+jsp环境写的文件上传,但是在将页面 ...

  4. 01_3_创建一个Action

    01_3_创建一个Action 1. 定义一个action 具体视图的返回可以由用户自己定义的Action来决定 具体的手段是根据返回的字符串找到相应的配置项,来决定视图的内容 具体Action的实现 ...

  5. 【点分治】luoguP2664 树上游戏

    应该是一道中等难度的点分?麻烦在一些细节. 题目描述 lrb有一棵树,树的每个节点有个颜色.给一个长度为n的颜色序列,定义s(i,j) 为i 到j 的颜色数量.以及 现在他想让你求出所有的sum[i] ...

  6. 【贪心】bzoj1577: [Usaco2009 Feb]庙会捷运Fair Shuttle

    一类经典的线段贪心 Description 公交车一共经过N(1<=N<=20000)个站点,从站点1一直驶到站点N.K(1<=K<=50000)群奶牛希望搭乘这辆公交车.第i ...

  7. day 35 补充

      MySQL数据库初识   MySQL数据库 本节目录 一 数据库概述 二 MySQL介绍 三 MySQL的下载安装.简单应用及目录介绍 四 root用户密码设置及忘记密码的解决方案 五 修改字符集 ...

  8. python中文件操作的其他方法

    前面介绍过Python中文件操作的一般方法,包括打开,写入,关闭.本文中介绍下python中关于文件操作的其他比较常用的一些方法. 首先创建一个文件poems: p=open('poems','r', ...

  9. WPF触控程序开发(三)——类似IPhone相册的反弹效果

    用过IPhone的都知道,IPhone相册里,当图片放大到一定程度后,手指一放,会自动缩回,移动图片超出边框后手指一放,图片也会自动缩回,整个过程非常和谐.自然.精确,那么WPF能否做到呢,答案是肯定 ...

  10. BZOJ 4355: Play with sequence

    调了好久,还是黑盒测试有前途 我以前怕不是学了假的吉利线段树(我第一次知道还要记次小值去更新的........) #include<cstdio> #include<algorith ...