【问题标题】:add pins to custom image将引脚添加到自定义图像
【发布时间】:2012-10-01 21:08:28
【问题描述】:

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

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

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

【问题讨论】:

    标签: iphone ios5 xcode4.2


    【解决方案1】:
    UIImageView* marker = [[UIImageView alloc] initWithImage: myMarkerImage];
    [marker setCenter: CGPointMake(250,150)];
    [myScrollView addSubview: marker];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-31
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      相关资源
      最近更新 更多