我使用一個的NSMutableArray獲取特定的SuperView的所有子視圖,一切正常,但日誌說:排序意見
superView contains (
"<UIView: 0x68795c0; frame = (20 172; 238 115); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x689aad0>>",
"<UIView: 0x6e67d90; frame = (143 295; 115 115); autoresize = W+H; layer = <CALayer: 0x6e67dc0>>",
"<UIView: 0x6e6f1a0; frame = (20 49; 115 115); autoresize = W+H; layer = <CALayer: 0x6e6e830>>",
"<UIView: 0x6e6fac0; frame = (143 49; 115 115); autoresize = W+H; layer = <CALayer: 0x6e6faf0>>"
)
正如你所看到的,看來的意見是裝隨機進入數組,但對我來說重要的是它們按順序加載,所以它從超級視圖的頂部到底部加載視圖。因此,它應該這個樣子:
superView contains (
"<UIView: 0x6e6f1a0; frame = (20 49; 115 115); autoresize = W+H; layer = <CALayer: 0x6e6e830>>",
"<UIView: 0x6e6fac0; frame = (143 49; 115 115); autoresize = W+H; layer = <CALayer: 0x6e6faf0>>"
"<UIView: 0x68795c0; frame = (20 172; 238 115); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x689aad0>>",
"<UIView: 0x6e67d90; frame = (143 295; 115 115); autoresize = W+H; layer = <CALayer: 0x6e67dc0>>",
)
誰能給我如何做到這一點建議嗎?
你是什麼意思,他們應該加載「爲了」?你需要排序哪個屬性或關鍵字? – Carter
@Carter對不起,我認爲數組應該從屏幕的頂部到底部加載這些視圖,例如,以ax座標爲0的視圖首先出現,480視圖最後一個 – kopproduction
下面的答案描述瞭如何對數組進行排序,但是這裏的一個重要提示是'subviews'不是隨機的。它的順序是z順序,這是繪圖的順序,以便視圖可以正確堆疊。你要求的是y順序,這對你的目的可能是有用的,但對繪圖沒有意義。 –