previewImage
接口说明
previewImage:options: 用于全屏预览图片,并支持图片浏览相关的手势交互,例如左右滑动切换图片等。
调用方需要通过 SUDOPPreviewImageOptions 传入当前展示图片地址以及图片地址列表。SDK 会根据配置打开图片预览页面,并优先展示 current 指定的图片。
类型声明
objectivec
/**
Options for configuring image preview behavior.
*/
@interface SUDOPPreviewImageOptions : NSObject
/**
The URL link of the currently displayed image.
This image will be shown first when the preview opens.
*/
@property(nonatomic, strong) NSString *current;
/**
The list of image URL links to be previewed.
Users can swipe left/right to browse through all images in this list.
*/
@property(nonatomic, strong) NSArray<NSString *> *urls;
@end方法声明
objectivec
/**
Previews an image in full-screen mode with support for gesture interactions.
@param stateHandle The state handle object that manages the operation state and callbacks.
@param options The options configuration for image preview (e.g., image URLs, current index, show save button).
*/
- (void)previewImage:(id<SUDOPStateHandle>)stateHandle
options:(SUDOPPreviewImageOptions *)options;参数说明
SUDOPPreviewImageOptions
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
current | NSString * | 否 | 当前显示图片的 URL 链接。打开预览时会优先展示该图片。 |
urls | NSArray<NSString *> * | 是 | 需要预览的图片 URL 链接列表,用户可左右滑动浏览列表中的图片。 |
方法参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
stateHandle | id<SUDOPStateHandle> | 是 | 状态句柄对象,用于管理当前操作状态及回调。 |
options | SUDOPPreviewImageOptions * | 是 | 图片预览配置对象,包含当前展示图片地址和图片地址列表。 |
使用示例
objectivec
id<SUDOPStateHandle> stateHandle = self.stateHandle;
SUDOPPreviewImageOptions *options = [[SUDOPPreviewImageOptions alloc] init];
options.current = @"https://example.com/images/1.png";
options.urls = @[
@"https://example.com/images/1.png",
@"https://example.com/images/2.png",
@"https://example.com/images/3.png"
];
[self previewImage:stateHandle options:options];处理流程
- 业务侧准备需要预览的图片 URL 列表。
- 创建
SUDOPPreviewImageOptions对象。 - 设置
options.urls为图片 URL 链接数组。 - 根据需要设置
options.current为打开预览时优先展示的图片 URL。 - 调用
previewImage:options:发起图片预览操作。 - SDK 打开全屏图片预览页面。
- 用户可通过左右滑动等手势浏览图片。
注意事项
stateHandle不应为空,否则 SDK 可能无法正确管理当前操作状态或回调。options不应为空。urls不应为空,且应至少包含一个有效的图片 URL。current一般应为urls中的某一项;如果未设置或不在urls中,SDK 可能默认展示urls中的第一张图片。urls中的图片地址可以是网络图片地址,也可以是 SDK 支持的本地图片路径,具体以实际实现为准。- 如果图片为网络地址,调用方应确保图片 URL 可正常访问。
- 该方法无同步返回值,预览状态或异常结果应以 SDK 回调或状态回调为准。
