How to replicate the iBook main screen in iOS?
I need to create a iBook main screen to allow users to select books from the cover view layout.
I am thinking to use a vertical UIScrollView layout to place the UIImageView objects. Is it a good approach ?
Another big question is : when a user deletes a book and a UIImageView object is removed from the screen, how to make the remaining UIImageView objects to re-organize and move with animation ?
Re-drawing the UIScrollView with the latest b开发者_如何学运维ook list could be acceptable, however, there will be no animation to show UIImageview objects to shift and move ?
Any good idea to solve the problems ?
You could have a UIScrollView with a NSMutableArray with the UIImageViews in it so, when you remove/add a book, you remove/add it from the array, then with a observer for changes you re-arrange the uiimagesviews with animation as needed.
Example:
-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self && [keyPath isEqualToString:@"ArrayofBooks"]) {
//Do animations here as needed
}
}
-(id)init {
//...Previous init
ArrayofBooks = [[NSMutableArray alloc] init];
[self addObserver:self forKeyPath:@"ArrayofBooks" options:0 context:NULL];
//...other init needed
}
This should go on your UIScrollView What it does is that registers an Mutable array and sets an observer for the changes on it, then the first method is called by the observer and you do your thing.
EDIT: Important!, when you add/remove an object you must do it the following way or else the Observer won't see it
[[self mutableArrayValueForKey:@"ArrayofBooks"] addObject:newBook];
[[self mutableArrayValueForKey:@"ArrayofBooks"] removeObject:newBook];
精彩评论