Specific features:
There is a uiimageview in one view, and when you press and hold Uiimageview, the picture represented by UIImage in Uiimageview is saved to PhotoAlbum.
Implementation: The code is as follows: Self.imageview is a defined Uiimageview view property
Long press Effect-(void) longpangesture { Uilongpressgesturerecognizer *longgesture = [[Uilongpressgesturerecognizer alloc] Initwithtarget:self </span>action: @selector (longpangesture:)]; [Self.imageview addgesturerecognizer:longgesture]; Longgesture.minimumpressduration = 4; [Longgesture release];}
Corresponding event: Longpangesture method implementation
-(void) Longpangesture: (Uilongpressgesturerecognizer *) longgesture { if (longgesture.state = = Uigesturerecognizerstatebegan) { uiimagewritetosavedphotosalbum ([Self.imageview image], nil, nil,nil); Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Save photos successfully" message:@ "photos are stored in picture library" Delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:nil]; [Alert show]; [Alert release];} }
Uiimagewritetosavedphotosalbum method
Uiimagewritetosavedphotosalbum is a function in the Uikit framework. Here's what the following three parameters mean: void Uiimagewritetosavedphotosalbum ( UIImage *image, ID completiontarget, SEL completionselector, void *contextinfo);/**id is the target object *sel is selector. The name of the method on the target object * ContextInfo is an arbitrary pointer that is passed to the method defined by the selector. * This is usually done when the method is called when it is finished, or when it is completed with an error. */
Original: Address
"Learn iOS: UI series" To save a picture to a photo album that comes with iOS