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];
}
如对本文有疑问, 点击进行留言回复!!
iOS14Beta3续航怎么样 iOS14Beta3续航能力介绍
iOS14Beta3稳定性怎么样 iOS14Beta3升级建议介绍
uniapp编写H5界面放入IOS全面屏原生导航栏盖住H5界面
游戏APP解决方案,8月1日起下架无版号ios手游的出路在哪?
网友评论