UIView順時針旋轉、逆時針旋轉

    因爲項目需求,須要作點擊向下剪頭時,剪頭逆時針旋轉180度,再點擊,順時針旋轉180度(恢復原位)動畫

    由於個人基礎不牢固,遇到這種知識點的問題就百度,可是網上找到的全是逆時針旋轉,想改爲順時針,第一反應是把旋轉角度前加「-」,惋惜無果。後來,試了幾個角度值,終於實現的UIView的順時針旋轉code


逆時針旋轉:orm

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

順時針旋轉:it

        //順時針 旋轉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度以後(也就是執行一遍這個方法),再執行一遍,應該是迴歸原位。可是不知道爲何沒有。多是跟設置座標相似吧,它旋轉的時候不是以如今的角度爲基準進行旋轉,而是必定固定好要旋轉到的角度。我如今是這麼理解的。項目忙,沒時間細深究,等有空要好好研究一下iOS的各類動畫效果以及參數。
io

相關文章
相關標籤/搜索