IOS开发(90)之动画视图的旋转
1 前言
今天我们来学习如何创建一个旋转仿射变换并使用 uiview 类的动画方法来执行旋转动作。
2 代码实例
zyviewcontroller.m
[plain]
- (void)viewdidload
{
[super viewdidload];
uiimage *xcodeimage = [uiimage imagenamed:@"xcode.png"];
self.xcodeimageview = [[uiimageview alloc] initwithimage:xcodeimage];
//设置图片的frame
[self.xcodeimageview setframe:cgrectmake(0.0f,0.0f, 100.0f, 100.0f)];
self.view.backgroundcolor = [uicolor whitecolor];
[self.view addsubview:self.xcodeimageview];
}
- (void) viewdidappear:(bool)paramanimated{ [super viewdidappear:paramanimated];
self.xcodeimageview.center = self.view.center;
/* begin the animation */
[uiview beginanimations:@"clockwiseanimation" context:null];
/* make the animation 5 seconds long */
[uiview setanimationduration:5.0f];
[uiview setanimationdelegate:self];
//停止动画时候调用clockwiserotationstopped方法
[uiview setanimationdidstopselector:@selector(clockwiserotationstopped:finished:context:)];
//顺时针旋转90度
self.xcodeimageview.transform = cgaffinetransformmakerotation((90.0f * m_pi) / 180.0f);
/* commit the animation */
[uiview commitanimations];
}
- (void)clockwiserotationstopped:(nsstring *)paramanimationid finished:(nsnumber *)paramfinished
context:(void *)paramcontext{
[uiview beginanimations:@"counterclockwiseanimation"context:null];
/* 5 seconds long */
[uiview setanimationduration:5.0f];
/* 回到原始旋转 */
self.xcodeimageview.transform = cgaffinetransformidentity;
[uiview commitanimations];
}
推荐阅读
-
IOS开发(89)之动画之视图的缩放
-
IOS开发(90)之动画视图的旋转
-
实例讲解iOS应用UI开发之基础动画的创建
-
IOS开发教程第一季之UI进阶day8合并IOS学习019--敲击、长按、轻扫、旋转,CALayer、锚点,CADisolayLink刷新,核心动画,关键帧动画,组动画,转场动画,画板案例
-
IOS开发(89)之动画之视图的缩放
-
IOS开发(90)之动画视图的旋转
-
IOS开发代码分享之获取启动画面图片的string
-
实例讲解iOS应用UI开发之基础动画的创建
-
IOS开发教程第一季之UI进阶day8合并IOS学习019--敲击、长按、轻扫、旋转,CALayer、锚点,CADisolayLink刷新,核心动画,关键帧动画,组动画,转场动画,画板案例
-
IOS开发代码分享之获取启动画面图片的string