ScrollView があり、その中にスクロールできるマップがあります。
そのマップにカスタム ボタンを配置したいのですが、ImageView に配置した後、移動しないようにマップ上に 29 個のボタンが必要です。
すでに 13 個のボタンを配置しましたが、タッチに反応するのは 8 つだけで、他のボタンは反応しません。
奇妙なことに、8 つのうちの 1 つで、ボタン イメージの一番上に触れないと応答しません。
これは、Map 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];
}
}