动态实现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. Golang glog使用详解

    golang/glog 是 C++ 版本 google/glog 的 Go 版本实现,基本实现了原生 glog 的日志格式.在 Kuberntes 中,glog 是默认日志库. glog 的使用与特性 ...

  2. NIOP 膜你题

    NOIp膜你题   Day1 duliu 出题人:ZAY    1.大美江湖(mzq.cpp/c) [题目背景] 细雪飘落长街,枫叶红透又一年不只为故友流连,其实我也恋长安听门外足音慢,依稀见旧时容颜 ...

  3. ssh整合思想初步 structs2 Spring Hibernate三大框架各自要点

    Web层用Structs2的action Service层用Spring的IoC和aop以及JdbcTemplate或者Transaction事务(创建对象及维护对象间的关系) Dao层用Hibern ...

  4. paper:基于verilog HDL 的高速可综合FSM设计

    1.寄存器输出型状态机 VS 组合逻辑输出型状态机 2.状态编码方法 这块讲的不好,也比较少. 3.系统设计中模块划分的指导性原则

  5. PHP数组函数 array_multisort() ----对多个数组或多维数组进行排序

    PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...

  6. HMAC(Hash-based Message Authentication Code)实现原理

    1.HMAC 概念 HMAC(Hash-based Message Authentication Code)基于 hash 的消息验证码,是 安全通信中必要的组成部件. 主要是 防止消息被篡改,和对称 ...

  7. Do not pour out HDU - 5954 数学积分

    题目:题目链接 思路:纯高等数学问题,不过不是很好积分,具体积分思路及过程参考大佬博客——https://blog.csdn.net/danliwoo/article/details/53002695 ...

  8. hdu 5533

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  9. HDU 5371 Manacher Hotaru's problem

    求出一个连续子序列,这个子序列由三部分ABC构成,其中AB是回文串,A和C相同,也就是BC也是回文串. 求这样一个最长的子序列. Manacher算法是在所有两个相邻数字之间插入一个特殊的数字,比如- ...

  10. 【ajax】全面总结

    Ajax 的全面总结 2017-11-03 山外de楼 JavaScript Ajax在前端开发中有着举足轻重的地位,关于Ajax的使用和注意事项一直是一个重要的话题,借此机会,本文希望对Ajax做一 ...