当前位置: 移动技术网 > 移动技术>移动开发>IOS > IOS开发(90)之动画视图的旋转

IOS开发(90)之动画视图的旋转

2019年05月12日  | 移动技术网移动技术  | 我要评论

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]; 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网