關於旋轉(view的旋轉以及上面電池條選裝的方向)

2021-07-07 08:39:28 字數 1586 閱讀 8982

/*

1.view.transform一般是view的旋轉,拉伸移動等屬性,類似view.layer.transform,區別在於view.transform是二維的,也就是使用仿射的辦法通常就是帶有字首cgaffinetransform的類(可以到api文件裡面搜尋這個字首的所有類),而view.layer.transform可以在3d模式下面的變化,通常使用的都是字首為catransform3d的類

2.當你改變過乙個view.transform屬性或者view.layer.transform的時候需要恢復預設狀態的話,記得先把他們重置可以使用view.transform = cgaffinetransformidentity,或者view.layer.transform = catransform3didentity,假設你一直不斷的改變乙個view.transform的屬性,而每次改變之前沒有重置的話,你會發現後來的改變和你想要的發生變化了,不是你真正想要的結果

*/if (orientation == uiinte***ceorientationlandscapeleft) else

if (orientation == uiinte***ceorientationlandscaperight) else

if (orientation == uiinte***ceorientationportraitupsidedown) else

//以下也可以用block塊來實現

[uiview beginanimations:nil context:nil];

[uiview setanimationduration:duration];

//在這裡設定view.transform需要匹配的旋轉角度的大小就可以了。

[uiview commitanimations];

上面的方法是按照中心點旋轉,若想按照任意點旋轉對cgaffinetransform進行設定,(xy為控制項上的比例,例如想按照左上角選擇,x=0;y=0)

- (cgaffinetransform)getcgaffinetransformrotatearoundpoint:(uiview *)view x:(cgfloat)x y:(cgfloat)y

{ float centerx = view.bounds.size.width/2;

float centery = view.bounds.size.height/2;

x = x - centerx; //計算(x,y)從(0,0)為原點的座標系變換到(centerx ,centery)為原點的座標系下的座標

y = y - centery; //(0,0)座標系的右橫軸、下豎軸是正軸,(centerx,centery)座標系的正軸也一樣

cgaffinetransform trans = cgaffinetransformmaketranslation(x, y);

trans = cgaffinetransformrotate(trans,120.0/180.0*m_pi);

trans = cgaffinetransformtranslate(trans,-x, -y);

return trans;

關於通過螢幕旋轉確定view的layout的問題

之前在專案中,有乙個uiimageview需要通過接收螢幕旋轉的通知來計算它的大小及位置,開始我選擇接收 uideviceorientationdidchange 至此,這個關於螢幕旋轉的通知基本上就清楚了,如果你只關心水平和垂直之間的改變,那麼請選擇接收 所帶來的face up和face down...

關於Bitmap的旋轉

在原來的專案裡有表盤指標旋轉的需求,做出來的效果被我查出乙個小小bug 先貼 1 2 34 5 6 78 9 1011 1213 1415 1617 1819 2021 public void setrotate float degrees stick setimagebitmap ns rotat...

Android 縮放 移動 旋轉View相關方法

android rotation 關聯方法 setrotation float 屬性說明 旋轉度數 android rotationx 關聯方法 setrotationx float 屬性說明 水平旋轉度數 android rotationy 關聯方法 setrotationy float 屬性說明...