migari
migari

Reputation: 131

Creating "map" from my own image

I have my own jpg and I want to do something like that:

Declare areas, where after click such popup will show up. How can I do this? I've tried with map view, but I don't think that is correct.

Upvotes: 0

Views: 87

Answers (1)

spring
spring

Reputation: 18497

There are many ways to do want to accomplish but you don't provide enough specifics to determine which approach is most appropriate. (e.g. do you need to display these 'hotspot' areas graphically before or after they are clicked, etc.).

To take the most basic approach, you define an array of CGRect-based objects and then in a touch event, test if the touch point is inside any of the rects.

// many ways to define the rects
    NSMutableArray* hotspots; //this would be a @property declared elsewhere

// define 5 CGRects
    for (int i = 0; i < 5; i++) {
        NSValue *rectObj = [NSValue valueWithCGRect:CGRectMake(i * 10, 0, 44, 44)];
        [hotspots addObject:rectObj];
    }

// and to test for hits:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Detect touch anywhere
    UITouch *touch = [touches anyObject];

    for (NSValue* rectObj in hotspots) {
        if (CGRectContainsPoint([rectObj CGRectValue], point)){
            //this is a hit so do something

            break;
        }
    }
}

Upvotes: 2

Related Questions