Monday 15 June 2015

Need to restrict movement of UIImageView to region covered by UITableView using UIPanGestureRecognizer in iOS -


I am currently running a UIImageView in my application using a UIPanGestureRecognizer object. Currently, this UIImageView is moving up and down very well on my screen. However, what I would like to do now, I am restricting the limits of the movement of UIIMAVE, which is covered by my UTT Vu which is in the middle of the screen. I want to restrict this movement to both the upper and the lower limitations of the UITWEV. This is my relevant method where I control the movement of my UIImageView:

  - (zero) pengage detector: (UIPanGestureRecognizer *) identifier {_startLocation = [recognizer locationInView: _imageView]; NSLog (@ "dot:% d", _start location); CGPoint newCenter = _imageView.center; NewCenter.y = [Identifier Location Inview: [_ Image View Supervision]]. Y; // This is where I think I need to include a statement, to see that the location is within the desired area _imageView.center = newCenter; }   

I know that I need to include an "if" statement in my method, to see if my UIImageView is in my desired area, but the problem is That I'm not sure how anyone can help me to check this for?

You should use the translationInView method

This will return a location of CGPoint and move the user to the image. Compare the original position of the image view for translation. If the translation is too large, the view of the image will come out of the desired area, do not move it.

The code should look something like this (I think you can leave it right):

  CGPint translation = [identifier translate review: _imageView.superview]; [Identifier set conversion: CGPointMake (0, 0) Inview: _imageView.superview]; CGPET center = identifier View. center; Center.y + = translation.y; If (center.y & lt; _table.frame.origin.y || center.y> _table.frame.size.height) {return; } Identizer.view.center = Center;   

Look for alternative implementations.

No comments:

Post a Comment