我有一个 ScrollView,里面有一个可以滚动的地图。
在该地图上,我想放置自定义按钮,并且在将它们放置在 ImageView 上之后,我需要地图上的 29 个按钮不要移动。
我已经放置了 13 个按钮,但其中只有 8 个响应触摸,其他的只是不响应。
奇怪的是,您必须触摸按钮图像的最顶部才能响应的 8 个之一。
这是因为我需要将地图 ImageView 和按钮放置在一个 ContainerView 中,然后再放置在 ScrollView 中吗?
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.positionArray = [[NSMutableArray alloc] init];
CGRect node1 = CGRectMake(290, 90, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node1]];
CGRect node2 = CGRectMake(238, 159, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node2]];
CGRect node3 = CGRectMake(290, 136, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node3]];
GRect node4 = CGRectMake(341, 159, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node4]];
...
CGRect node11 = CGRectMake(166, 318, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node11]];
CGRect node12 = CGRectMake(290, 264, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node12]];
CGRect node13 = CGRectMake(413, 318, 30, 30);
[self.positionArray addObject:[NSValue valueWithCGRect:node13]];
//self.positionArray = nil;
self.nodeArray = [[NSMutableArray alloc] init];
for(int i = 0; i < [positionArray count]; i++)
{
//Create the button
UIButton *button = [[UIButton alloc] initWithFrame:[[self.positionArray objectAtIndex:i] CGRectValue]];
[button setImage:[UIImage imageNamed:@"GreenNode.gif"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"Bigger.gif"] forState:UIControlStateHighlighted];
[button setUserInteractionEnabled:YES];
[self.nodeArray addObject:button];
}
for(UIButton *button in self.nodeArray)
{
//add the button to the view
[self.mapView addSubview:button];
//add the action
//[button addTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchDown];
}
}