Tap and hold to save image in UIWebview

2019-06-14 16:26发布

In my app I have a UIWebView that shows a list of pictures. Right now, when someone taps and holds their finger on a picture, the option comes up to copy that picture.

Is there a way to make it so that, when someone taps and holds, the option to save that picture appears?

Any ideas are welcomed!

1条回答
贼婆χ
2楼-- · 2019-06-14 17:01

You need to detect the long tap. For that you need to add:

 @property (nonatomic,strong) UILongPressGestureRecognizer *lpgr;

and in your view did load:

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

[self.view addGestureRecognizer:self.lpgr];

and ask the user to save the picture once the app detects the long tap.

   - (void)handleLongPressGestures:(UILongPressGestureRecognizer *)sender
{
    if ([sender isEqual:self.lpgr]) {
        if (sender.state == UIGestureRecognizerStateBegan)
        {  
           //prompt the user to save the picture .
        }
    }
}
查看更多
登录 后发表回答