Drag to implement a picture move effect
Write a gesture first, and note that the userinteractionenabled of the image is set to Yes
uipangesturerecognizer *pan = [[uipangesturerecognizeralloc] Initwithtarget:selfAction:@selector(pan:)] ;
UIImage *image = [UIImageimagenamed:@ "r.jpg"];
uiimageview *imageview = [[uiimageviewalloc] initwithframe:cgrectmake (ten, A, A, a)];
ImageView. image = image;
ImageView. userinteractionenabled =YES;
[selfaddsubview: ImageView];
[ImageViewAddgesturerecognizer:p an];
}
Drag the method, the last sentence is the key code
-(void) pan: ( Uipangesturerecognizer *) gesture
{
cgpoint point = [gesture- Translationinview: self];
Gesture.view . center =cgpointmake (Gesture.view . center . x + point. x , gesture. view . center . y + point. y );
[Gesture settranslation:cgpointmake(0,0) InView : Self ];
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Drag to implement a picture move effect