iOS PdfKit select and delete note annotation when long pressed/tapped - ios

I am adding annotations to a pdf document and this works as expected. Now I also want to delete them and here I am facing some issues.
As I see, it should work out of the box, but when I long click on an annotation mostly of the time the text around of it is being selected but not the annotation itself.
This is one example where I created a big annotation so that I am sure that my finger is not touching any text around of it. When I long click on it this is what I get most of the time (this is not always, sometimes the menu also appears over the annotation and I am able to delete it via the delete action):
I also tried to add a long-press/tap gesture on the PDFKit and in these situations when I long click on the annotation and the text is being selected, my long press gesture is not being fired. I assume that the view hierarchy inside PDFKit is causing this issue.
With the tap gesture I am able to detect the annotation when it's being tapped, but in this case the controller?? that is displaying the annotation text is not being shown (I guess because I intercept the tap gesture). Is there a way to still trigger the annotation display and modify the controller (add additional navigation button since now there is just a "Done" button)? This is the particular controller when I tap the orange note icon:
Adding hightlight annotations to text and removing them works as expected (because there is no problem with selecting text)
Is there a way to somehow force the PDFKit to mark the annotation as selected when I long click on it? Modifying the controller that is being displayed when an annotation is being tapped would also help.

In case somebody else is struggling with this.
I chose to display the annotation inside a custom controller.
First I implemented a TapGestureRecognizer on the pdfview, from there got the annotation and then displayed the annotation inside the custom controller.

Related

Go to next controller without using CallOutForAccessory MKMapview

I have a map view in that I am showing annotations. On clicking any annotation the callout (bubble with info) will appear above the annotation.
What I want is to navigate to another class by clicking the callout without using CallOutForAccessory delegate method. I have added touch gesture in didselect but it still didn't work. I have looked through the Internet but didn't find any solution for the same. Most of the solutions compromise of CallOutForAccessory. Please share your ideas if anyone has done this before.

Using single UIView I want to manage tap action based on location and update specific object

enter image description here
I am making app like sudoku (9*9 boxes) but it has only binary choices (on/off) and using button gave me horrible results. Can anyone give me demo version of 9*9 (or 3*3) box where depending upon the tap location, that specific box gets toggled (on/off)
You could create a custom subclass of UIView that had an attached tap gesture recognizer and interpreted the tap location to figure out which cell is being tapped, but it would be a lot of work.
It would be better to have custom view that contains a grid of buttons and set up the button actions to do what you want.
You said "...using button gave me horrible results." Can you elaborate? That should be a good way to go, so any "horrible results" are likely the result of something you did wrong, rather than that being the wrong way to go.

Hiding button in annotation callout Swift

I am wondering how I can hide and show a button in an annotation callout?
I set up my annotation view to have a left and a right button, each doing a separate task. The user can add an annotation by selecting a location from a table or long press.
I want the left button to be accessible and the right button to be hidden when the annotation is added via selection from table and the left button to be hidden the the right button to be accessible when the annotation is added via long press.
I have the buttons in the callout working but I can't figure how how to hide/show them. Any help is much appreciated!
Don't use a generic MapAnnotation object. Create a custom object that conforms to the MKAnnotation protocol and give it an Enum property that has a different value if it's added from your table or from a long press.
In your viewForAnnotation method, cast the annotation object to your custom type and check the property before deciding which callouts to add. (You'll need special-case code for the user location, as always.)

Adding Custom Image on Mkannotationview, or on callout bubble?

i'm trying to reproduce the kind of map behavior of the app "Stuck On Earth". Here's a screenshot :
Here's the behavior :
On the map, as you can see there is pin
When you click on a pin, it display the picture attach to it. Really important : the picture stai with the pin, and it stays BEHIND it
If you click on the picture, a new controller is called
if you click on the pin, the picture disappear
I'm trying to do something similar. For now, as i can read, i've got two solutions :
Using callout : callout is HELL. I can try to use a false annotation, but MapKit deals with the depth of elements, and the picture is always in front of the pin
Using Custom Annotation : i was going for the plan of making custom annotation view, when the pin is tapped, i launch a method of the CustomAnnotationView, adding (or removing) the thumbnail.
I think the method number 2 could work, but i've got no idea how to deal with the touch on the thumbnail.
Any suggestions or help on this ?
Thanks you !
Updated 2016-09-02:
My colleague devised an workaround by making popup views as subview of the view container which contains the map view. The position can be calculated according to the CGPoint transform in different reference systems.
Original Answer:
I also got this kind of problem, after following the tutorial 'Building Custom Map Annotation Callouts – Part 1', the interaction becomes difficult.
Have you tried the tap gesture recognizer? I added it to a subview, it works, although the code smell bad.

clearButton not working in UITextEditField

This is one of those "it was working a while ago" troubleshooting efforts.
I'm working on the document preview view controller, in which is a scroll view, which itself contains subclasses of UIView that represent each document. I'm modeling this pretty closely to how Keynote handles its document preview, except I build my scroll view horizontally and with paging. But the standard user experience is present: Long press on a document icon causes all document icons to start jiggling, nab bar has + button and Edit button, etc.
The issue at hand is that when you tap on the name of a document, I hide all the others, move the one being edited front and center, build a new text edit field, add it as a subview atop the real name label, and set it as first responder; but the
[editNameTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
while correctly showing in the edit field is not taking any action when the user taps on the clear button.
I can't figure out what I may have done to cause this to not work -- it had been!
My first thought was that somehow my instance of this subclass is no longer the delegate for this text edit field. To try and confirm/deny that, I usurped a tap on the image view of the document preview to compare the delegate property to self, and it passes.
if (editNameTextField) {
NSLog(#"editNameTextField is still active");
if ([editNameTextField.delegate isEqual:self]) {
NSLog(#"we're still the delegate for the editNameTextField");
}
}
Editing the text within the edit field works fine. Pressing the Return/Done key correctly sends the delegate message textFieldShouldReturn:
While investigating this I implemented the delegate method textFieldShouldClear: just to write a log message if the method gets called (and return YES of course). It never gets called.
My next thought was that perhaps a subview had covered up the area where the clear button sits. So I implemented textFieldShouldBeginEditing: and used the opportunity to bring my the text field to the front. That didn't change anything either. I set a debugger breakpoint there to play a sound when it was called, and it got called, so I know my text edit field is frontmost.
I have only one troubleshooting strategy remaining: Go backwards through snap shots until it starts working again. Before doing that I thought I'd see if any of the more experienced folks out here have any suggestions of what to try next.
Where are you adding the textfield? As a subview of the scrollView? If you added the textfield and it is out of bounds of its parent view it won't receive any touches.
You can try and not call becomeFirstResponder and see if clicking it will show keyboard. Another possible error might be that the parent view of the UITextField has userInteractionEnabled = NO.
Without seeing more code I'm afraid I can not offer more solutions.

Resources