この画像の上にimageviewと半透明のボタンを備えたscrollViewがあります。[addsubview]でスクロールビューにボタンとイメージビューを追加します。ここで、イメージビューとボタンの位置を変更する必要があります (フレーム プロパティを変更します)。
エス:
button.frame = CGRectMake( x, y, w, h );
これを行うと、ボタンが非表示になります。ボタンの位置だけを変えれば完璧に動作します。
PS: 私は今、bringtofront を使用しようとしました。
スクロールビュー コンテンツの作成:
int index = 0;
int x = OFFSETXCOPERTINA;
int y = 0;
int w = LARGHEZZACOPERTINA;
int h = ALTEZZACOPERTINA;
int riga = 0;
int indexriga = 0;
int testindex = 0;
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown) {
testindex = NRCopertineVerticale;
}
else {
testindex = NRCopertineOrizzontale;
}
for (NSDictionary *rigaordine in ElencoOrdini)
{
if (indexriga > 0) x = x + OFFSETXCOPERTINA + w;
y = OFFSETYCOPERTINA + (riga * (h + OFFSETYCOPERTINA));
UIButton *buttonCopertina = [UIButton buttonWithType:UIButtonTypeCustom];
buttonCopertina.frame = CGRectMake(x, y, w, h);
[buttonCopertina setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(255/255.0) blue:(0/255.0) alpha:0.3]];
UIImage *image = [[UIImage alloc] initWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: [NSString stringWithFormat: @"%@image.php?CODe=%@", URLXXX, [rigaordine objectForKey:@"cod_isb"]]]]];
UIImageView *copertina = [[UIImageView alloc] initWithImage: image];
[copertina setTag:TAGCopertine + index];
[copertina setFrame:CGRectMake(x, y, w, h)];
[buttonCopertina setTag:TAGButtonCopertine + index];
[buttonCopertina addTarget:self action:@selector(buttonCopertinaClicked:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:copertina];
[scrollView addSubview:buttonCopertina];
index++;
indexriga++;
if (indexriga >= testindex) {
indexriga = 0;
riga++;
x = 10;
}
}
iPadを回転させると:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
int index = 0;
int x = OFFSETXCOPERTINA;
int y = 0;
int w = LARGHEZZACOPERTINA;
int h = ALTEZZACOPERTINA;
int riga = 0;
int indexriga = 0;
int testindex = 0;
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown) {
testindex = NRCopertineVerticale;
}
else {
testindex = NRCopertineOrizzontale;
}
for(int j = 0; j< 999; j++) {
if (indexriga > 0) x = x + OFFSETXCOPERTINA + w;
y = OFFSETYCOPERTINA + (riga * (h + OFFSETYCOPERTINA));
UIImageView *copertina = (UIImageView *)[self.scrollView viewWithTag:(TAGCopertine + j)];
if (copertina != nil) {
copertina.frame = CGRectMake( x, y, LARGHEZZACOPERTINA, ALTEZZACOPERTINA );
}
UIButton *button = (UIButton *)[self.scrollView viewWithTag:(TAGButtonCopertine + j)];
if (button != nil) {
button.frame = CGRectMake( x, y, LARGHEZZACOPERTINA, ALTEZZACOPERTINA );
}
index++;
indexriga++;
if (indexriga >= testindex) {
indexriga = 0;
riga++;
x = 10;
}
}
}