1

I took one custom view (SignatoryView) on pdf, When I click on Add button from Navigation bar, it will add that SignatoryView on PDF view and according to my choice I can move/drag that signatory view to any location.

Problem: When I am moving that signatory view on pdf, it is going outside edges of pdfView. (Left, right, bottom and top also)

It should not go beyond its boundaries, it should be movable only inside edges on PDF view.

How I can achieve this ? Here is the complete project code

Nikita Patil
  • 674
  • 1
  • 7
  • 17

1 Answers1

1

You just need to get half of the width and half of the height of your signature and when setting the new center position of it add or subtract it from the origin x and/or y:

let minX = frame!.width/2
let minY = frame!.height/2
let maxX = pdfView.frame.width-minX
let maxY = pdfView.frame.height-minY
customView1?.center = CGPoint(
    x: min(maxX, max(minX, touchLocation!.x)),
    y: min(maxY ,max(minY, touchLocation!.y)))
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • Dear @Leo I was working similar kind of example, I am facing one issue, Can u check it once, if u can able to solve my problem. Here is the link - https://stackoverflow.com/questions/64444911/how-i-can-move-drag-multiple-views-on-pdf-view – Nikita Patil Oct 22 '20 at 05:47
  • Feel free to ask another question and comment the link here if you would like me to take a look at it – Leo Dabus Oct 22 '20 at 05:50
  • @NikitaPatil if this doesn't help let me know https://stackoverflow.com/a/56729268/2303865 – Leo Dabus Oct 22 '20 at 06:13
  • I achieved that moving/dragging any view on pdf. Now in that code, the current problem is there i.e I m not getting where I have to write the code (your answer on this current problem) for to restrict the position. Can u check it, once and let me know. Here is code - https://drive.google.com/file/d/1G_MS2hpl3YFbA8k9VlLTjilRO653nwHF/view?usp=sharing – Nikita Patil Oct 22 '20 at 09:19
  • sir have u checked my new project ? – Nikita Patil Oct 22 '20 at 10:30
  • @NikitaPatil https://stackoverflow.com/a/64492705/2303865 – Leo Dabus Oct 23 '20 at 03:05
  • Leo Dabus sir, there is one more new question I created, similar to this question only. Can you please check it, I know 100 %, you have a solution for that question, because last time you only gave an idea to implement this feature. Here is the link for new question - https://stackoverflow.com/questions/71015338/restrict-to-move-drag-the-pdf-annotation-within-pdf-page-boundary – Nikita Patil Feb 07 '22 at 08:50