IOS _ long-pressed Save image, ios Save image
Finally:
Sample code snippet
//// ViewController. m // long press, the menu controller is displayed to download the image /// Created by beyond on 15-3-26. // Copyright (c) 2015 beyond.com All rights reserved. // # import "ViewController. h "@ interface ViewController () @ property (weak, nonatomic) IBOutlet UIImageView * imageView; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // added the long-pressed gesture UILongPressGestureRecognizer * longTap = [UILongPressGestureRecogniz Er alloc] initWithTarget: self action: @ selector (longTap :)]; [self. view addGestureRecognizer: longTap];} // added long-pressed gesture-(void) longTap :( UILongPressGestureRecognizer *) reco {if ([reco state] = UIGestureRecognizerStateBegan) {[[reco view] locate]; CGPoint loc = [reco locationInView: nil]; UIMenuController * mCtrl = [UIMenuController sharedMenuController]; UIMenuItem * item = [UIMenuItem alloc] in ItWithTitle: @ "save" action: @ selector (saveClick :)]; [mCtrl setMenuItems: [NSArray arrayWithObject: item]; // There is a problem !!!! // CGPoint loc = reco. [mCtrl setTargetRect: CGRectMake (loc. x, loc. y-20, 0, 0) inView: [reco view]; [mCtrl setMenuVisible: YES animated: YES] ;}// must implement-(BOOL) canBecomeFirstResponder {return YES ;} -(BOOL) canPerformAction :( SEL) action withSender :( id) sender {if (action = @ selector (saveClick :)) {return YES;} return NO; // hide the default menu items} // Add a long-pressed gesture-(void) saveClick :( id) sender {if (self. imageView. image) {UIImageWriteToSavedPhotosAlbum (self. imageView. image, nil); UIImageWriteToSavedPhotosAlbum (self. imageView. image, self, @ selector (image: didFinishSavingWithError: contextInfo :), nil) ;}// execute when the file is written to complete-(void) image :( UIImage *) image metadata :( NSError *) error contextInfo :( void *) contextInfo {// [SVProgressHUD showSuccessWithStatus: @ "image saved"]; // UIButton * btn = (UIButton *) [_ footView viewWithTag: VHelpDetailFootViewBtnTypeFont]; // btn. enabled = YES ;}# pragma mark-supplemental download image-(void) downBtnClick :( UIButton *) btn {UIButton * btn = (UIButton *) [_ footView viewWithTag: done]; btn. enabled = NO; if ([_ currentPhoto underlyingImage]) {// directly write to the file [self writeImgToFile];} else {// change to the new remote download image [self downloadImgAsync] ;}}// download image # import "SDWebImageDecoder. h "# import" SDWebImageManager. h "# import" SDWebImageOperation. h "-(void) downloadImgAsync {// Load async from web (using SDWebImage) [SVProgressHUD progress: @" saving images "]; @ try {[[SDWebImageManager sharedManager] downloadImageWithURL: [NSURL URLWithString: _ currentImgUrl] options: 0 progress: ^ (NSInteger receivedSize, NSInteger expectedSize) {if (expectedSize> 0) {float progress = receivedSize/(float) expectedSize; NSDictionary * dict = [NSDictionary Syntax: [NSNumber numberWithFloat: progress], @ "progress", self, @ "photo", nil]; [[nsicationicationcenter defacenter] postNotificationName: Your object: dict] ;}} completed: ^ (UIImage * image, NSError * error, SDImageCacheType cacheType, BOOL finished, NSURL * imageURL) {if (error) {MWLog (@ "SDWebImage failed to download image: % @", error);} // write to the file UIImageWriteToSavedPhotosAlbum (image, self, @ selector (image: didFinishSavingWithError: contextInfo :), nil) ;}] ;}@ catch (NSException * e) {MWLog (@ "Photo from web: % @", e) ;}@ end