I have got a MapView with some custom MKAnnotation, MKAnnotationView which I use to create nice custom callout.
Anyway, for my main Annotation Pin, I use some nice image of pins with a pre-rendered shadow on their left.
However, I would like the annotation not to get selected when the user touch its shadow. Because when their are a lot of them, the shadow of one can overlap another, and the wrong one gets selected because the shadow gets touched.
I have tried to use a separate image for the shadow and put it in a UIImageView inside the MKAnnotationView but it does not change anything, even if I put enableUserInteraction = NO.
any idea?
Make your MKAnnotationView the size of the image excluding the shadow. Change it's frame so that it encompasses the part you want it to receive touch. The shadow should exceed this frame, but shouldn't be cut off.
Related
I'm trying to divide one image to a more than one clickable part. for example, if the image is a body image, and I tapped the head, it should take me to a different the HeadViewController, but if I tapped on the left hand, it should take me to a different view controller
Any idea how to do that?
Easy method:
Add UIButtons on top of the image with clear background color. You can do this with AutoLayout and always get correct proportions to the areas when scaling up and down.
Hard method:
Add UITapGestureRecognizer to the UIImageView and calculate CGPoint depending on where it the touchPoint is received. This is complicated and must be calculated correctly.
For you, I suggest the first method suggested.
Attach a tap gesture recognizer to your image view. Set user interaction enabled to true.
In the handler for the tap gesture, fetch the coordinates of the user's tap and write custom code that figures out which "hot box" the user tapped in.
Alternately you could create a custom subclass of UIGestureRecognizer that has multiple tap regions.
Our UIView contains a MapBox map. At certain moments during our apps lifespan we display a UIView on top of the Map.
This view had a transparant background and a couple of controls inside it. What we want is to be able to drag the map on the spots where the view is transparent. (It should basically pass through the gestures to the view below it..which is the map).
To get a basic picture of what we try to accomplish: think of a map and above it is a view which shows a big + sign. What we want is when we drag the actual sign...nothing happens. But when you drag in the empty corners, it should drag the map.
Any ideas how to accomplish that?
Check out -[UIView userInteractionEnabled] and set it to NO for the transparent view. Be sure to set it to YES for the control subviews. That should do the trick.
I ran into a problem while building a map app. I'm trying to do the following:
add an animated PNG sequence as overlay to the map so that it appears to be "on the map" while the user changing the zoom, rotation and pitch of the map.
on top of that PNG sequence I would like to show a custom pin image, using MKAnnotationView.
So far, what I've been able to do is:
Load PNG sequence into an UIImageView and animate them.
add the UIImageView to the MKMapView, using addSubView:.
Detect changes to the MKMapView and update the position of UIImageView accordingly
However, if I start adding MKAnnotations to the MapView, they get added below my UIImageView (see image on the left).
Is there a way to add them on top of the UIImageView (see image on the right)?
?
I want to add multiple pins on map which should remain animated continuously. Below are sample images which I want to use as Pin,
Is there any possible way to get this type of animated pin within MapKit? If possible then please suggest me appropriate way for it.
As per my knowledge it is quite tough to implement. You can easily implement animation on any UIImageView but when you add any image on custom image then you can change custom pin image via using KVO or via NSTimer.
Please follow Animation with MapView Custom Pin link to better understanding with custom pin annotation.
You can change pin image too after a certain period of time like as Zooming change pin image
and Custom pin animation - MKMapView.
I hope it will help you to better understanding. Thanks
You could create a custom MKAnnotationView and give it a UIImageView as a subview.
Then, split the GIF into separate frames, to use in the UIImageView, as documented in this SO question.
i am working on a project in which i have added a UIimageview to show an image selected by user. Now requirement is that if user want to crop an images it can touch the image according to crop requirement. when user cropping the image a line should draw at place where user has touched. i know that UITouch class will use for it. But i am unable to do it.
A couple of possible solutions.
1) Create a custom UIView that contains a UIImageView as it's subview. Make the UIImageView be the same size as the custom UIView. Then add code to detect the touches on the custom UIView and draw the lines on top of the UIImageView subview.
2) Create a custom clone of UIImageView that draws the image first as the 'background' and then detects the touches and draws the lines on top of the image.
Also make sure you have userInteractionEabled set to YES on the view receiving the touches.