CGTransform简单使用,包括平移,旋转,缩放

旋转:

-(void)Rotate:(UIButton *)rotate

{

//位移(不累加)

//self.headImageView.transform=CGAffineTransformMakeTranslation(50, 200);

//缩放

//self.headImageView.transform=CGAffineTransformMakeScale(1.2, 10);

//在原有的基础上位移(是累加的)

//self.headImageView.transform=CGAffineTransformTranslate(self.headImageView.transform, 50, 50);

//在原有的基础上进行缩放

//self.headImageView.transform=CGAffineTransformScale(self.headImageView.transform, 1.5, 1.6);

//在原有的基础上进行旋转

if (rotate.tag) {

//旋转角度为1/pi,逆时针

self.headImageView.transform=CGAffineTransformRotate(self.headImageView.transform, -M_1_PI);

}

else

{

//旋转的角度为pi/2,顺时针

self.headImageView.transform=CGAffineTransformRotate(self.headImageView.transform, M_PI_2);

}

}

缩放:

-(void)Zoom:(UIButton *)btn

{

//使用bounds,以中心点位原点进行缩放

CGRect bounds = self.headImageView.bounds;

if (btn.tag) {

bounds.size.height+=30;

bounds.size.width+=30;

}

else

{

bounds.size.height-=50;

bounds.size.width-=50;

}

//设置首尾动画

[UIView beginAnimations:nil context:nil];

self.headImageView.bounds=bounds;

[UIView setAnimationDuration:2.0];

[UIView commitAnimations];

}

平移:

//控制方向的多个按钮调用同一个方法

-(void)Click:(UIButton *)button

{

//练习使用frame属性

//CGRect frame=self.headImageView.frame;

/**注意,这里如果控制位置的两个属性frame和center同时使用的话,会出现很好玩的效果,注意分析*/

//练习使用center属性

CGPoint center=self.headImageView.center;

switch (button.tag) {

case ktopbtntag:

center.y-=30;

break;

case kdownbtntag:

center.y+=30;

break;

case kleftbtntag:

//发现一个bug,之前的问题是因为少写了break,造成了它们的顺序执行,sorry

//center.x=center.x-30;

center.x-=50;

break;

case krightbtntag:

center.x+=50;

break;

}

//  self.headImageView.frame=frame;

//首尾式设置动画效果

[UIView beginAnimations:nil context:nil];

self.headImageView.center=center;

//设置时间

[UIView setAnimationDuration:2.0];

[UIView commitAnimations];

NSLog(@"移动!");

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • VLC的集成和使用 VLC介绍 VLC Media Player (VideoLAN) 为 Windows、Lin...
    Pocket阅读 19,979评论 75 66
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,595评论 6 30
  • 1.transform属性 在OC中,通过transform属性可以修改对象的平移、缩放比例和旋转角度 常用的创建...
    SacredBillows阅读 1,386评论 0 0
  • 前言 本文只要描述了iOS中的Core Animation(核心动画:隐式动画、显示动画)、贝塞尔曲线、UIVie...
    GitHubPorter阅读 3,673评论 7 11
  • 1、改变 UITextField 占位文字 颜色和去掉底部白框 [_userName setValue:[UICo...
    i_MT阅读 1,076评论 0 2