[分享]iOS开发-UIView顺时针旋转、逆时针旋转

逆时针旋转:

    //arrowLeft 是要旋转的控件
    //逆时针 旋转180度 
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2]; //动画时长
    arrowLeft.transform = CGAffineTransformMakeRotation(180 *M_PI / 180.0);
    CGAffineTransform transform = arrowLeft.transform;
    //第二个值表示横向放大的倍数,第三个值表示纵向缩小的程度
    transform = CGAffineTransformScale(transform, 1,1);
    arrowLeft.transform = transform;
    [UIView commitAnimations];
    

顺时针旋转:

    //顺时针 旋转180度
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.2]; //动画时长
    arrowLeft.transform = CGAffineTransformMakeRotation(0*M_PI/180);
    CGAffineTransform transform = arrowLeft.transform;
    transform = CGAffineTransformScale(transform, 1,1);
    arrowLeft.transform = transform;
    

正常想法,一个控件经历一次顺时针旋转180度之后(也就是执行一遍这个方法),再执行一遍,应该是回归原位。但是不知道为什么没有。可能是跟设置坐标类似吧,它旋转的时候不是以现在的角度为基准进行旋转,而是一定固定好要旋转到的角度。

分享来源:
http://my.oschina.net/irisoO/…

    原文作者:ShevaKuilin
    原文地址: https://segmentfault.com/a/1190000004522377
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞