:
(1) UIImageView .
(2) UIImageView, UIPanGestureRecognizer. - :
self.panRecognizer =
[[UIPanGestureRecognizer alloc]
initWithTarget: self
action: @selector(handlePan:)];
[self addGestureRecognizer:
self.panRecognizer];
(3) In the action method associated with the pan gesture recognizer, update the location of the object based on the messages from the tin plate recognizer. Something like the following should work:
-(void) handlePan:
(UIGestureRecognizer *)sender
{
UIPanGestureRecognizer *panRecognizer =
(UIPanGestureRecognizer *)sender;
if (panRecognizer.state ==
UIGestureRecognizerStateBegan ||
panRecognizer.state ==
UIGestureRecognizerStateChanged)
{
CGPoint currentPoint =
self.center;
CGPoint translation =
[panRecognizer translationInView:
self.superView];
self.center = CGPointMake
(currentPoint.x + translation.x,
currentPoint.y + translation.y);
[panRecognizer setTranslation: CGPointZero
inView: self.superView];
}
}
source
share