1

如何在自定义图像上添加可点击的图钉或类似图钉?让用户在单击图像或视图上的图钉(可能是文本框)的位置添加注释。

在我的代码中,我在图像上添加了静态弹出窗口,我希望我能找到方法让用户在单击图像的任何部分时让他添加 pin 或类似 popup 的东西。

  I use this code to add popup to the image 
(part of the code ) self.visiblePopTipViews = [NSMutableArray array];

    self.contents = [NSDictionary dictionaryWithObjectsAndKeys:
                     // Rounded rect buttons
                     @"Play Ground", [NSNumber numberWithInt:1],
                     @"HeadMaster", [NSNumber numberWithInt:2],
                     @"Science Faculty", [NSNumber numberWithInt:3],
                     @"Accounting Faculty", [NSNumber numberWithInt:4],
                     @"Economy Faculty", [NSNumber numberWithInt:5],
                     @"Cultive Faculty", [NSNumber numberWithInt:6],
                     @"Tourisim Faculty", [NSNumber numberWithInt:7],
                     @"Swimming Pool ", [NSNumber numberWithInt:8],
                     @"Medicine Faculty", [NSNumber numberWithInt:9],
                     @"Engeneering Faculty", [NSNumber numberWithInt:10],
                     @"IT Faculty", [NSNumber numberWithInt:11],
                     nil];

    // Array of (backgroundColor, textColor) pairs.
    // NSNull for either means leave as default.
    // A color scheme will be picked randomly per CMPopTipView.
    self.colorSchemes = [NSArray arrayWithObjects:
                         [NSArray arrayWithObjects:[NSNull null], [NSNull null], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor darkTextColor], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor blueColor], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
                         nil];
     scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    scroll.backgroundColor = [UIColor blackColor];
    scroll.delegate = self;

     zoomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, scroll.contentSize.width, scroll.contentSize.height)];
    zoomView.backgroundColor = [UIColor whiteColor];

    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]];

    scroll.contentSize = image.frame.size;
    [scroll addSubview:image ] ; 

    UIButton *playGround = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [playGround addTarget:self 
                   action:@selector(buttonAction:)
         forControlEvents:UIControlEventTouchDown];
    [playGround setTitle:@"playGround" forState:UIControlStateNormal];
    playGround.tag = 1 ; 
    playGround.frame = CGRectMake(290.0, 170.0, 80.0, 40.0);
    [image addSubview:playGround];

    UIButton *masterBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [masterBtn addTarget:self 
                  action:@selector(buttonAction:)
        forControlEvents:UIControlEventTouchDown];
    [masterBtn setTitle:@"Presidency" forState:UIControlStateNormal];
    masterBtn.tag = 2 ; 
    masterBtn.frame = CGRectMake(250.0, 270.0, 60.0, 30.0);
    [image addSubview:masterBtn];
4

1 回答 1

3
UIImageView* marker = [[UIImageView alloc] initWithImage: myMarkerImage];
[marker setCenter: CGPointMake(250,150)];
[myScrollView addSubview: marker];
于 2012-11-07T10:07:06.290 回答