在代码中表示的 `HSImageSidebarView
` 是 `UIView
` 的子类,用于显示图像集合。这些图像根据视图的维度以水平或垂直方式排列。它支持选择、滚动、拖动和重新排列以及拖动删除。API 是以 `UITableView
` 为模板设计的,因此对 Cocoa Touch 程序员来说是熟悉的。HSImageSidebarView 与 iPad 和 iPhone 界面风格都兼容。
可以使用 `UIView
` 上的标准 `initWithFrame:
` 方法创建 `HSImageSidebarView
`。
// Create an 80-pixel sidebar on the left side of the screen
HSImageSidebarView *sidebar = [[HSImageSidebarView alloc] initWithFrame:CGRectMake(0, 0, 80, 1004)];
sidebar.delegate = self;
[parentView addSubview:sidebar];
[sidebar release];
还可以使用 Interface Builder 创建,通过添加 `UIView
` 并将其类(在 IB 中)设置为 `HSImageSidebarView
` 完成。
图像侧边栏通过代理方法接收所有信息。两个必需的方法是这些:
- (NSUInteger)countOfImagesInSidebar:(HSImageSidebarView *)sidebar;
- (UIImage *)sidebar:(HSImageSidebarView *)sidebar imageForIndex:(NSUInteger)anIndex;
当用户点击、移动或删除图像时,委托可以通过以下方法之一来通知
- (void)sidebar:(HSImageSidebarView *)sidebar didTapImageAtIndex:(NSUInteger)anIndex;
- (void)sidebar:(HSImageSidebarView *)sidebar didMoveImageAtIndex:(NSUInteger)oldIndex toIndex:(NSUInteger)newIndex;
- (void)sidebar:(HSImageSidebarView *)sidebar didRemoveImageAtIndex:(NSUInteger)anIndex;
HSImageSidebarView
需要 iOS 4.0 或更高版本。包含一个示例项目,以演示用法。
以下是我希望实现但尚未完成的功能