点击并按住以在UIWebview中保存图像

Lod*_*pps -1 image objective-c uiwebview

在我的应用程序中,我有一个显示图片列表的UIWebView.现在,当有人用手指敲击图片时,可以选择复制该图片.

是否有办法使它,当有人点击并保持时,出现保存该图片的选项?

欢迎任何想法!

Tej*_*uri 5

您需要检测长按.为此你需要添加:

 @property (nonatomic,strong) UILongPressGestureRecognizer *lpgr;
Run Code Online (Sandbox Code Playgroud)

并在您的视图中加载:

  self.lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
self.lpgr.minimumPressDuration = 1.0f;
self.lpgr.allowableMovement = 100.0f;

[self.view addGestureRecognizer:self.lpgr];
Run Code Online (Sandbox Code Playgroud)

并在应用检测到长按时要求用户保存图片.

   - (void)handleLongPressGestures:(UILongPressGestureRecognizer *)sender
{
    if ([sender isEqual:self.lpgr]) {
        if (sender.state == UIGestureRecognizerStateBegan)
        {  
           //prompt the user to save the picture .
        }
    }
}
Run Code Online (Sandbox Code Playgroud)