I have a UIView with several UIImages (subviews) that holds photos that the user choose from the photo library. I want to support a feature where the user can rearrange the order of the subviews. The user gets a modalviewcontroller, where he can drag and drop the views in order and place it in place. But when I want to update the order of the subviews nothing happens. The only thing that succeeds is placing the object I drag to the top using bringSubviewToFront:, but that's not what I want.
The method I want to use is exchangeSubviewAtIndex:i withSubviewAtIndex:index
. But I can't get it to work. Do you guys have any suggestions of how I should tackle this?
Thanks in advance! Michael
You mention "dropping an image in a new place" , this implies you are moving the UIImageView in the (X,Y) co-ordinate system. The index in the subviews array orders the views only in the Z direction (effecting which is "on top" if they overlap). Swapping view order will not swap the (X,Y) coordinates.
Its an app where you have a stack of images (overlapped) that you can watch a sequence of.
I use ELCImagePicker, an extension of the camera roll, which allows us to select multiple images in the camera roll.
I get the returned images in a dictionary like so:
for(NSDictionary *dict in info) {
UIImageView *thisImageView = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];
[array insertObject:thisImageView atIndex:[thearray count]];
[thisImageView release];
}
I then push a view controller which shows me the right images – it shows my UIView subclass, SpinnerView
Inside SpinnerView, i lay out the subviews:
spinnerImages = [[NSMutableArray alloc] initWithArray:thearray];
for (UIView *object in spinnerImages) {
[object setContentMode:UIViewContentModeScaleAspectFit];
object.frame = self.frame;
[self addSubview:object];
}
When the user wants to manage the order, they click an "edit button" and get a modalViewController, an instance of the AQGridView library, which works like a tableViewController, but with some extensions. It works like a springboard app. When the user "drops" an image to a new place, I call
[spinnerView exchangeSubviewAtIndex:_dragOriginIndex withSubviewAtIndex:index];
, just after the table have updated the array:
// update the data store
id obj = [[images objectAtIndex: _dragOriginIndex] retain];
[images removeObjectAtIndex: _dragOriginIndex];
[images insertObject: obj atIndex: index];
Hope this helps to solve my puzzle a rid me of my headache:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.