怎样实现UIView的旋转
首先创建界面,在viewDidLoad创建view以及button
相关代码如下
-(void)viewDidLoad
{
[super viewDidLoad];
viewDemo = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 50)];
[viewDemo setBackgroundColor:[UIColor brownColor]];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
label.text =@"Test";
label.tag=100;
[viewDemo addSubview:label];
[self.view addSubview:viewDemo];
[label release];
// Do any additional setup after loading the view, typically from a nib.
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 400, 100, 50)];
[btn setBackgroundColor:[UIColor blueColor]];
btn.showsTouchWhenHighlighted = YES;
[btn setTitle:@"点击旋转" forState:UIControlStateNormal];
[self.view addSubview:btn];
btn.tag = 10010;
[btn addTarget:self action:@selector(testViewDemo) forControlEvents:UIControlEventTouchUpInside];
[btn release];
number = 0;
}
-(void)testViewDemo
{
number++;
if (number%3 == 0) {
CGAffineTransform at = CGAffineTransformMakeRotation(M_PI/2);
at = CGAffineTransformTranslate(at, 200, 0);
[viewDemo setTransform:at];
}else if (number%3 ==1 ){
CGAffineTransform at = CGAffineTransformMakeRotation(M_PI/1);
at = CGAffineTransformTranslate(at, 0, 0);
[viewDemo setTransform:at];
}else if(number%3 ==2){
CGAffineTransform at = CGAffineTransformMakeRotation(M_PI*2);
at = CGAffineTransformTranslate(at, 0, 0);
[viewDemo setTransform:at];
}
}
-(void)testViewDemo
{
//旋转,左旋
number++;
CGAffineTransform rotate = CGAffineTransformMakeRotation(number / 180.0 * M_PI );
[viewDemo setTransform:rotate];
}
如果使用此方法连续点击button就可以显示处一点一点的移动效果
每次旋转90度的话可以使用一下的代码实现效果
-(void)testViewDemo
{
//旋转,右旋
number = number+90.0;
CGAffineTransform rotate = CGAffineTransformMakeRotation(number / 180.0 * M_PI );
[viewDemo setTransform:rotate];
}
UIView实现左旋效果
//旋转,左旋
number = number-90.0;
CGAffineTransform rotate = CGAffineTransformMakeRotation(number / 180.0 * M_PI );
[viewDemo setTransform:rotate];
通过以上的讲解,我想,关于点击UIButton实现UIView的旋转大家就可以轻松的操作了。
传送门:
http://jingyan.baidu.com/article/3aed632e7164b070108091de.html
怎样实现UIView的旋转的更多相关文章
- UIView 的旋转和缩放
原文地址:http://www.cnblogs.com/gaoxiao228/archive/2012/05/04/2483577.html label.transform = CGAffineTra ...
- UIView动画效果之----翻转.旋转.偏移.翻页.缩放.取反的动画效
翻转的动画 //开始动画 [UIView beginAnimations:@"doflip" context:nil]; //设置时常 [UIView setAnimationDu ...
- View页面内容的旋转,在某些情况下可替代屏幕旋转使用
这个是在做小秘书的体重曲线图的时候用到的,横排的时候可以多显示些内容,可是由于很多未知的冲突导至屏幕旋转起来非常麻烦,可用用旋转页面的内容来达到旋转屏幕的效果. 代码如下: //旋转90度 CGAff ...
- ios开发--旋转、移动、缩放手势实例代码
代码如下: // 添加所有的手势 - (void) addGestureRecognizerToView:(UIView *)view { // 旋转手势 UIRotationGestureRecog ...
- UIView的基本属性及ANimation
frame属性:可以使用该属性改变尺寸和位置 相对于父视图bounds:改变尺寸 相对自身center:改变视图的位置alpha:改变视图的透明度backgroundColor:改变视图的背景cont ...
- 使用手势对UIImageView进行缩放、旋转和移动
// 添加所有的手势 - (void) addGestureRecognizerToView:(UIView *)view { // 旋转手势 UIRotationGestureRecognizer ...
- 旋转动画用控件RotateView
旋转动画用控件RotateView 最终效果: 源码: RotateView.h 与 RotateView.m // // RotateView.h // RotateAnimationView // ...
- 使用手势对UIImageView进行缩放、旋转和移动(转)
原文地址:http://blog.csdn.net/crazy_frog/article/details/8664108 // 添加所有的手势 - (void) addGestureRecognize ...
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
随机推荐
- 经常遇到Please ensure that adb is correctly located at 'D:\java\sdk\platform-tools\adb.exe' and can be e
遇到问题描述: 运行android程序控制台输出 [2012-07-18 16:18:26 - ] The connection to adb is down, and a severe error ...
- 从一个小项目看return 引用 重载运算符
#ifndef _ARRAY_H_ #define _ARRAY_H_ class Array { private: int mLength; int* mSpace; public: Array(i ...
- struts复合类型传值(对象传值)
01:导包,配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version ...
- paper 85:机器统计学习方法——CART, Bagging, Random Forest, Boosting
本文从统计学角度讲解了CART(Classification And Regression Tree), Bagging(bootstrap aggregation), Random Forest B ...
- DOM事件处理有三个阶段
DOM事件处理有三个阶段: 捕捉阶段(capture phase):从最上层元素,直到最下层(你点击的那个target)元素.路过的所有节点都可以捕捉到该事件. 命中阶段(target phase): ...
- 更改EBS APPS 密码流程
更改EBS APPS 密码流程 (更改完后重启APP 和DB)2008-1-4 在EBS11.5.10.2环境应用成功! 参考metalink Note:160337.1 How To Manual ...
- 使用java访问 动态链接库(dll)
在这个时候,我们可以使用的java技术有jni.jna.jnative,这个大部分都可以完成任务.但是有时候我们在实际情况中拿到的dll有变化,当我们需要用的函数是在dll中的类里面的话,我们再使用前 ...
- 关于UIView(转)
曾经有人这么说过,在iphone里你看到的,摸到的,都是UIView,所以UIView在iphone开发里具有非常重要的作用.那么UIView我们到底知道多少呢.请看看下面的问题, 如果这些你都知道, ...
- linux端口
1.查看开放的端口 netstat -anp 来查看哪些端口被打开. 注:加参数'-n'会将应用程序转为端口显示,即数字格式的地址,如:nfs->2049, ftp->21,因此可以开启两 ...
- linux设备驱动归纳总结(五):1.在内核空间分配内存【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-79134.html linux设备驱动归纳总结(五):1.在内核空间分配内存 xxxxxxxxxxxx ...