HomeiOS Developmentios - Can we get click on or faucet occasion and alter...

ios – Can we get click on or faucet occasion and alter colour of PDFAnnotation with having picture on it


I’m attempting so as to add pdfannotation inside pdfview with picture solely, the place I would like faucet occasion of that specific iamge annotation that I’ve added. Can anybody recommend any method to obtain this. as a result of I would like particular faucet or chosen occasion of that. so after that I can in a position to change picture colour or any contents and so forth.

At the moment I’m utilizing this as creating picture inside PDFAnnotation.

`class ImageStampAnnotation: PDFAnnotation {

var picture: UIImage!

// A customized init that units the kind to Stamp on default and assigns our Picture variable
init(with picture: UIImage!, forBounds bounds: CGRect, withProperties properties: [AnyHashable : Any]?) {
    tremendous.init(bounds: bounds, forType: PDFAnnotationSubtype.stamp, withProperties: properties)
    
    self.picture = picture
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been carried out")
}


override func draw(with field: PDFDisplayBox, in context: CGContext) {
    
    // Get the CGImage of our picture
    guard let cgImage = self.picture.cgImage else { return }
    
    // Draw our CGImage within the context of our PDFAnnotation bounds
    context.draw(cgImage, in: self.bounds)
    
}

}`

Including faucet gesture inside my viewDidLoad to pdfview to get faucet space. And utilizing faucet gesture I’m attempting to fetch tapped occasion space to the closest annotation.

`
var annotations: [PDFAnnotation] = []
@objc func handleTap(_ sender: UITapGestureRecognizer) {

    guard sender.state == .ended else { return }

    let touchLocation = sender.location(in: pdfView)
    
    guard let page1 = pdfView!.web page(for: touchLocation, nearest: true)
    else {
        return
    }
            
    // Convert the faucet location to the PDF coordinate system
    let pdfPoint = pdfView.convert(touchLocation, to: page1)

    // Discover the annotation on the tapped location
    let annotationsAtPoint = page1.annotation(at: pdfPoint)//page1!.annotations(at: pdfPoint)
    if let annotation = annotationsAtPoint,
       let index = annotations.firstIndex(of: annotation) {
        annotations[index].colour = .crimson
        pdfView.setNeedsDisplay()
        print("Tapped on annotation at index (index)")
        print(annotations[index].contents)
        print(annotations[index].fieldName)
        print(annotations[index].bounds)
    }

}`

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments