ios旋轉螢幕總結 詳細教程

2021-06-09 01:43:29 字數 1124 閱讀 6690

第一種:通過人為的辦法改變view.transform的屬性。

具體辦法:

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

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

3.設定我們的view的中心點

cgpoint center = cgpointmake(frame.origin.x + ceil(frame.size.width/2), frame.origin.y + ceil(frame.size.height/2));

4.根據當前電池條的方向,獲取需要旋轉的角度的大小。通常

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

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

[uiview commitanimations];

第二種:通過setorientation:的辦法強制性的旋轉到乙個特定的方向。

//強制橫屏

if ([[uidevice currentdevice] respondstoselector:@selector(setorientation:)])

IOS螢幕旋轉

本部分 感謝原作者分享!螢幕旋轉學習筆記 加速計是整個ios螢幕旋轉的基礎,依賴加速計,裝置才可以判斷出當前的裝置方向,ios系統共定義了以下七種裝置方向 typedef ns enum nsinteger,uideviceorientation 以及如下四種介面方向 typedef ns enum...

iOS 螢幕旋轉

cpp view plain copy void willrotatetointe ceorientation uiinte ceorientation tointe ceorientation duration nstimeinterval duration else cpp view plain...

iOS螢幕旋轉

專案需求是在導航欄基類下保持豎屏,步驟如下 第一步如下圖,表示裝置只支援豎屏 第二步,通過繼承導航類建立乙個類,在該類裡面實現以下方法 bool shouldautorotate uiinte ceorientationmask supportedinte ceorientations 然後在導航子...