Wednesday, 15 April 2015

ios - Moving UIView within Parent UIView (UIPanGestureRecognizer) -


I am using the following code to move UIImageView that exists inside a UIView. - (IBAction) Handlain: (UIPNG® Accelerator *) Identifier {CGPint Translation = [Identifier Translation Visa]; Recognizer.view.center = CGPEXMake (see referrer .center .x + translate .x, identifier, see center.Y + translation.); [Identifier set conversion: CG pointmack (0, 0) Inview: Self. Observation];

}

I would like to do this so that UIView could not exit the parent view. In the minute the view of the image is able to go full screen.

Get the first new frame of your UIImageView and check whether it's your superView Inside the CGRectContainsRect () method is using. If so, set the UImageView's frame to a new frame.

  - (IBAction) Handlain: (UIPanGestureRecognizer *) Identifier {CGPoint Translation = [Identifier Translation Inview: self.view]; CGRect identifierframe = identifier View.frame; RecognizerFrame.origin.x + = translation.x; Identifier fram.origin.i + = translate Y; // Check that if UIImageView is completely inside your supervision (CGRCTinstance (self view, Bound, IdentifierFrame)) {identizer.view.frame = Identifier frame; } // Check otherwise if the UIImageView is horizontally outside of Vertical and / or its // Superview, if so, then set the Frame for UImageView accordingly. // It is necessary that when the user hovers faster it provides a smooth translation. Else {// Check pending (identifier frame.organ.A.self.view.bounds.origin.y) {identizerFrame.origin.y = 0; } And if (recognizerFrame.origin.y + identifier frame.ize.height> self.view.bounds.size.height) {identizerFrame.origin.y = self.view.bounds.size.height - recognizerFrame.size. Height; } // horizantally check if (identifierFrame.origin.x  self.view.bounds.size.width) {identifierFrame.origin.x = self.view.bounds.size.width - recognizerFrame.size. Width; }} // Reset the translation so that we get the correct translation value on the next pan validation [identifier set translate: CGPXMake (0, 0) Inview: Self. Weave]; }   

Make sure that you pass bound superView and frame to UIImageView so that both CGRTX is in the same coordinate system.

No comments:

Post a Comment