Skip to content

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 ​

参数类型是否必填说明
currentNSString *否当前显示图片的 URL 链接。打开预览时会优先展示该图片。
urlsNSArray<NSString *> *是需要预览的图片 URL 链接列表,用户可左右滑动浏览列表中的图片。

方法参数 ​

参数类型是否必填说明
stateHandleid<SUDOPStateHandle>是状态句柄对象,用于管理当前操作状态及回调。
optionsSUDOPPreviewImageOptions *是图片预览配置对象,包含当前展示图片地址和图片地址列表。

使用示例 ​

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];

处理流程 ​

  1. 业务侧准备需要预览的图片 URL 列表。
  2. 创建 SUDOPPreviewImageOptions 对象。
  3. 设置 options.urls 为图片 URL 链接数组。
  4. 根据需要设置 options.current 为打开预览时优先展示的图片 URL。
  5. 调用 previewImage:options: 发起图片预览操作。
  6. SDK 打开全屏图片预览页面。
  7. 用户可通过左右滑动等手势浏览图片。

注意事项 ​

  • stateHandle 不应为空,否则 SDK 可能无法正确管理当前操作状态或回调。
  • options 不应为空。
  • urls 不应为空,且应至少包含一个有效的图片 URL。
  • current 一般应为 urls 中的某一项;如果未设置或不在 urls 中,SDK 可能默认展示 urls 中的第一张图片。
  • urls 中的图片地址可以是网络图片地址,也可以是 SDK 支持的本地图片路径,具体以实际实现为准。
  • 如果图片为网络地址,调用方应确保图片 URL 可正常访问。
  • 该方法无同步返回值,预览状态或异常结果应以 SDK 回调或状态回调为准。