0

我有一个带有多个 UIImages(子视图)的 UIView,其中包含用户从照片库中选择的照片。我想支持用户可以重新排列子视图顺序的功能。用户得到一个模态视图控制器,他可以在其中按顺序拖放视图并将其放置到位。但是当我想更新子视图的顺序时,什么也没有发生。唯一成功的是将我拖动到顶部的对象使用bringSubviewToFront:,但这不是我想要的。

我要使用的方法是exchangeSubviewAtIndex:i withSubviewAtIndex:index. 但我无法让它工作。你们对我应该如何解决这个问题有什么建议吗?

提前致谢!迈克尔

4

2 回答 2

0

您提到“在新位置放置图像”,这意味着您正在 (X,Y) 坐标系中移动 UIImageView。subviews 数组中的索引仅在 Z 方向上对视图进行排序(如果它们重叠,则影响“在顶部”)。交换视图顺序不会交换 (X,Y) 坐标。

于 2011-06-01T02:26:18.313 回答
0

它是一个应用程序,您可以在其中查看一系列图像(重叠)。

我使用ELCImagePicker,一个相机胶卷的扩展,它允许我们在相机胶卷中选择多个图像。

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

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

然后我推送一个视图控制器,它显示了正确的图像——它显示了我的 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];

希望这有助于解决我的难题,让我摆脱头痛:)

于 2011-06-01T06:40:45.167 回答