I have a UIImage that is shown in a UIImageView . I also have another image in the UIImageView that lies above the first image. I want to be able to drag the second image only within the borders of the first image. To make my goal clearer, look at this image:
.
The green pin should be draggable, but it should not be possible to drag the pin to blue (outside the map). You can drag this icon right now, but I don’t know how to check if this icon is outside the map.
UPDATE: I used this method in my UIImageView subclass for drag and drop pins:
- (UIColor *)colorAtPosition:(CGPoint)position { CGRect sourceRect = CGRectMake(position.x, position.y, 1.f, 1.f); CGImageRef imageRef = CGImageCreateWithImageInRect([[MapViewController sharedMapViewController]getImage].CGImage, sourceRect); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); unsigned char *buffer = malloc(4); CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big; CGContextRef context = CGBitmapContextCreate(buffer, 1, 1, 8, 4, colorSpace, bitmapInfo); CGColorSpaceRelease(colorSpace); CGContextDrawImage(context, CGRectMake(0.f, 0.f, 1.f, 1.f), imageRef); CGImageRelease(imageRef); CGContextRelease(context); CGFloat r = buffer[0] / 255.f; CGFloat g = buffer[1] / 255.f; CGFloat b = buffer[2] / 255.f; CGFloat a = buffer[3] / 255.f; free(buffer); return [UIColor colorWithRed:r green:g blue:b alpha:a]; }
MapViewController is the Viewcontroller where the UIIImageView for the map is located. So I made this class a singleton to get a map image. But again, the meanings that I get for the color are completely related. I also updated the photo because my user interface has become a bit different.
source share