簡體   English   中英

objective-c 管理子視圖的訂單

[英]objective-c managing order for subviews

我有一個 UIView 和幾個 UIImages(子視圖),其中包含用戶從照片庫中選擇的照片。 我想支持用戶可以重新排列子視圖順序的功能。 用戶得到一個模態視圖控制器,他可以在其中按順序拖放視圖並將其放置到位。 但是當我想更新子視圖的順序時,什么也沒有發生。 唯一成功的是將 object 我使用bringSubviewToFront:拖到頂部,但這不是我想要的。

我想使用的方法是exchangeSubviewAtIndex:i withSubviewAtIndex:index 但我無法讓它工作。 你們對我應該如何解決這個問題有什么建議嗎?

提前致謝! 邁克爾

您提到“將圖像放在新位置” ,這意味着您正在(X,Y)坐標系中移動 UIImageView。 subviews 數組中的索引僅在 Z 方向上對視圖進行排序(如果它們重疊,則影響“在頂部”)。 交換視圖順序不會交換 (X,Y) 坐標。

它是一個應用程序,您可以在其中查看一系列圖像(重疊)。

我使用 ELCImagePicker,相機膠卷的擴展,它允許我們在相機膠卷中 select 多個圖像。

我在字典中得到返回的圖像,如下所示:

for(NSDictionary *dict in info) {
        UIImageView *thisImageView = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
        [array insertObject:thisImageView atIndex:[thearray count]];
        [thisImageView release];
}

然后我推送一個視圖 controller,它顯示了正確的圖像——它顯示了我的 UIView 子類 SpinnerView

在 SpinnerView 中,我列出了子視圖:

spinnerImages = [[NSMutableArray alloc] initWithArray:thearray];
for (UIView *object in spinnerImages) {
    [object setContentMode:UIViewContentModeScaleAspectFit];
    object.frame = self.frame;
    [self addSubview:object];
}

當用戶想要管理訂單時,他們單擊“編輯按鈕”並獲得一個modalViewController,它是AQGridView 庫的一個實例,它的工作方式類似於tableViewController,但有一些擴展。 它就像一個跳板應用程序。 當用戶將圖像“拖放”到新位置時,我會調用

[spinnerView exchangeSubviewAtIndex:_dragOriginIndex withSubviewAtIndex:index];

,就在表更新數組之后:

// update the data store
    id obj = [[images objectAtIndex: _dragOriginIndex] retain];
    [images removeObjectAtIndex: _dragOriginIndex];
    [images insertObject: obj atIndex: index];

希望這有助於解決我的難題,讓我擺脫頭痛:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM