UIWebView, enable touch hold save image, like in mobile Safari

柔情痞子 提交于 2019-12-21 06:36:26

问题


I'd like to enable Save Image and Copy when a user touch-holds an image in a UIWebView in my app. Is there a property that will enable this or will I need to write some special methods to accomplish this?

Thanks for reading!


回答1:


UIImage * downloadImage = [[UIImage alloc] initWithContentsOfFile:path];
    UIImageWriteToSavedPhotosAlbum(downloadImage,nil, nil, nil);
    [downloadImage release];

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Saved" message:@"Wallpaper saved to your Gallery." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];

    [alert show];
    [alert release];

Add this whole code to your long press method, it will save your image in gallery.



回答2:


You can start off by creating and attaching the UILongPressGestureRecognizer instance to the button.

 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
 [self.button addGestureRecognizer:longPress];
 [longPress release];

And then implement the method that handles the gesture

 - (void)longPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {
     NSLog(@"Long Press");

 //do something
   }
 }


来源:https://stackoverflow.com/questions/12912617/uiwebview-enable-touch-hold-save-image-like-in-mobile-safari

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