Tap and hold to save image in UIWebview

感情迁移 提交于 2019-12-10 12:25:42

问题


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:


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 .
        }
    }
}


来源:https://stackoverflow.com/questions/31522037/tap-and-hold-to-save-image-in-uiwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!