动态实现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. a survey for RL

    • A finite set of states St summarizing the information the agent senses from the environment at eve ...

  2. BCB:AnsiString BSTR WideString

    WideString wstr;AnsiString astr;wchar_t *wp;//或者 BSTR wp; wp=wstr.c_bstr(); //WideString转化为BSTRwstr= ...

  3. vue 报错unknown custom element解决方法

    原因: 没有引入相关组件导致的 解决办法: 如果组件是按需引入的必须引入你当前用到的组件,否则会报错

  4. Linux常用命令-----------------磁盘挂载命令

    磁盘挂载: [root@sdw1 ~]# mkfs.ext4 /dev/vdb[root@sdw1 ~]# blkid /dev/vdb >> /etc/fstabvi /etc/fsta ...

  5. abaqus中的约束

    1.tie -绑定约束:作用是将模型的两部分区域绑定在一起,二者之间不发生相对运动,相当于焊在一起. 2.rigid body--刚体约束--使一个模型区域刚体化,这个区域可以是一系列节点,单元等,刚 ...

  6. JDBC操作数据库的详细步骤

    1.注册驱动 告知JVM使用的是哪一个数据库的驱动 2.创建连接 使用JDBC中的类,完成对MySQL数据库的连接 3. 得到执行sql语句的Statement对象 通过连接对象获取对SQL语句的执行 ...

  7. php代码压缩

    php代码压缩,除可以使用token_get_all进行压缩之外,还可以使用系统自带的函数   php_strip_whitespace (PHP 5) php_strip_whitespace — ...

  8. Java-JFrame可视化开发

    Java-JFrame可视化开发的一般步骤 JFrame可以做出类似于QQ登录功能的窗体,通过JFrame可以利用Java代码实现窗体功能,一般用于CS项目的C(客户端)的开发: 利用JFrame可以 ...

  9. 创建 Django 步骤

    1.创建项目 django-admin startproject 项目名称 2.创建APP python manage.py startapp app名称 3.修改settings.py文件 3.1设 ...

  10. Redis的安装、服务配置

    在网上找了很多资料,有些可以正常安装,有些安装会出毛病,仔细想了想,还是自己整理一份吧,仅仅为自己下次再用的时候,能够快速的定位到可以正常用的文章! 我使用的是VMware Workstation P ...