Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Restringir para mover/arrastrar la anotación pdf dentro de los límites de la página PDF

Estoy cargando un PDF en la vista PDF usando la biblioteca del kit de PDF. Agregué una vista personalizada (igual que la anotación de PDF) en la vista de pdf, y permito que los usuarios muevan/arrastren esa vista personalizada en la vista de pdf (dentro de la vista de pdf/vista de contenedor) usando UIPanGestureRecognizer. Aquí hay un gif,

Si ves este gif, hay un problema. Esa vista personalizada va fuera de la página pdf. Quiero restringirlo. La vista personalizada debe moverse/arrastrarse solo dentro de la página pdf. ¿Cómo puedo arreglar esto? ¿Hay una solución para eso?

Aquí está el proyecto de muestra del enlace y todo el código: https://drive.google.com/file/d/1Ilhd8gp4AAxB_Q9G9swFbe4KQUHbpyGs/view?usp=sharing

Aquí hay una muestra de código del proyecto,

 override func didMoveToSuperview() { addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(pan))) } @objc func pan(_ gesture: UIPanGestureRecognizer) { translate(gesture.translation(in: self)) gesture.setTranslation(.zero, in: self) setNeedsDisplay() print("Frames after moving : \(frame)") }

y código usado como una extensión

 extension CGPoint { static func +(lhs: CGPoint, rhs: CGPoint) -> CGPoint { .init(x: lhs.x + rhs.x, y: lhs.y + rhs.y) } static func +=(lhs: inout CGPoint, rhs: CGPoint) { lhs.x += rhs.x lhs.y += rhs.y } } extension UIView { func translate(_ translation: CGPoint) { let destination = center + translation let minX = frame.width/2 let minY = frame.height/2 let maxX = superview!.frame.width-minX let maxY = superview!.frame.height-minY center = CGPoint( x: min(maxX, max(minX, destination.x)), y: min(maxY ,max(minY, destination.y))) } }

Código - Obtener alto y ancho de página PDF

 let page = pdfDocument.page(at: 0) let pageRect = page?.bounds(for: .mediaBox) print("pdf page width =", (pageRect?.size.width)!, "pdf page height =", (pageRect?.size.height)!)
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!