2012-10-11 123 views
1

如何在自定義圖像上添加可點擊圖釘或類似圖釘?讓用戶在圖像或視圖上單擊引腳(可能是文本框)添加註釋。將圖釘添加到自定義圖像

在我的代碼中,我在圖像上添加了靜態彈出框 我希望我能找到方法讓用戶在單擊圖像的任何部分時讓他添加引腳或類似彈出窗口的東西。

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]; 

回答

3
UIImageView* marker = [[UIImageView alloc] initWithImage: myMarkerImage]; 
[marker setCenter: CGPointMake(250,150)]; 
[myScrollView addSubview: marker]; 
相關問題