3D标签
动态实现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标签的更多相关文章
- 设计3D标签
java自带的Label太枯燥了,真是拿不出手啊. 所以,我们要设计3D标签!! 看看下面这张图 原理 看看这图,可以看到哈哈有三种颜色:白色.黑色和灰色 实现的时候并不像PS那样,按几个按钮就O了 ...
- css3实践之摩天轮式图片轮播+3D正方体+3D标签云(perspective、transform-style、perspective-origin)
本文主要通过摩天轮式图片轮播的例子来讲解与css3 3D有关的一些属性. demo预览: 摩天轮式图片轮播(貌似没兼容360 最好用chrome) 3D正方体(chrome only) 3D标签云(c ...
- SP2010 3D标签云Web部分--很酷的效果,强烈推荐!!
SP2010 3D标签云Web部分--很酷的效果.强烈推荐! ! 项目描述叙事 基于简单Flash的3D标签云Web部件.SP Server 2010使用. 建立在内置标签云Web部件 ...
- 解析3D标签云,其实很简单
声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢! 最近开始用canvas搞3D了,搞得也是简单的东西,就是球体转圈.做出来后,突然想起以前看过的3D标签云,在以前觉得真心狂拽酷炫叼啊,当时 ...
- jquery 3D 标签云
http://www.gbin1.com/technology/jquerynews/20111205tagcloudbyjquery/index.html 相关选项 zoom: 90 初始的缩放度 ...
- 【HMTL】3D标签球
这是一个3D TAG 在网站展示中是个不错的东东,能让人眼前一亮,值得收藏. 这个是效果: 源码下载: 点 击 下 载
- 纯JS实现的3D标签云,不依赖不论什么第三方库,支持移动页面
<span style="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html PUBLIC &q ...
- 3d标签云(JS版)
http://www.miaov.com/miaov_demo/3dLable/miaov_demo.html http://www.lijian.net/p/windstagball/index.h ...
- 3D标签云
一.圆的坐标表达式 for(var i = 0;i < len;i++){ degree = (2*(k+1)-1)/len - 1;a = Math.acos(degree);//这样取得弧度 ...
随机推荐
- Java中的后台线程和join方法
/*守护线程(后台线程):在一个进程中如果只剩下 了守护线程,那么守护线程也会死亡. 需求: 模拟QQ下载更新包. 一个线程默认都不是守护线程. */ public class Demo extend ...
- Java String Integer转换 练习:编程求字符串“100”和“150”按十进制数值做差后的结果以字符串形式输出。
package com.swift; public class String_To_Integer_Test { public static void main(String[] args) { /* ...
- 使用objection来模块化开发iOS项目
转自无网不剩的博客 objection 是一个轻量级的依赖注入框架,受Guice的启发,Google Wallet 也是使用的该项目.「依赖注入」是面向对象编程的一种设计模式,用来减少代码之间的耦合度 ...
- NOIP模拟赛 混合图
[题目描述] Hzwer神犇最近又征服了一个国家,然后接下来却也遇见了一个难题. Hzwer的国家有n个点,m条边,而作为国王,他十分喜欢游览自己的国家.他一般会从任意一个点出发,随便找边走,沿途欣赏 ...
- destoon 配置文件config.inc.php参数说明
$CFG['db_host']数据库服务器,可以包括端口号,一般为localhost $CFG['db_user']数据库用户名,一般为root $CFG['db_pass']数据库密码 $CFG[' ...
- 配置wamp开发环境之mysql的配置
此前我已经将wamp配置的Apache.PHP.phpmyadmin全部配置完成,以上三种配置参照 配置wamp开发环境 下面我们来看看mysql的配置,这里用的是mysql5.5.20,下载地址: ...
- Thinkphp 5 调试执行的SQL语句
在模型操作中 ,为了更好的查明错误,经常需要查看下最近使用的SQL语句,我们可以用getLastsql方法来输出上次执行的sql语句.例如: User::get(1); echo User::getL ...
- unix cc编译过程
1.编译并链接一个完全包含与一个源文件的C程序: cc program.c 这条命令产生一个称为a.out的可执行程序.中间会产生一个名为program.o的目标 ...
- LeetCode(123) Best Time to Buy and Sell Stock III
题目 Say you have an array for which the ith element is the price of a given stock on day i. Design an ...
- ubuntu12.04ppa安装emacs24
ppa地址:https://launchpad.net/~cassou/+archive/emacs 因为debian版本的emacs-snapshot维护者停止更新,所有ubuntu上的也停止了. ...