0

私は、さまざまなモジュールで構成されるアプリに取り組んでいます。開始ページから、これらのさまざまなモジュールに移動できます。

それらの 1 つは一種のイメージ ピッカーで、複数のイメージ サムネイルをボタンとして表示するビューです。

このサムネイルをクリックすると、ボタンでもある画像全体がサブビューに表示されます。

サムネイル ビューに戻るには、画像 (ボタン) をもう一度クリックするだけでよいはずです。

問題は、さまざまなモジュールから選択できる開始ページに常に戻るように指示されることです。

ここに、ViewController の実装があります。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
int counter;
int x = 30;
int y = 10;

for (counter = 1; counter < 9 ; counter++) {

UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

CGRect rect = CGRectMake(x, y, 307, 230);
imageButton.frame = rect;

[imageButton addTarget:self action:@selector(showImage:) forControlEvents:UIControlEventTouchUpInside];
[imageButton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tn%i.jpg",counter]] forState:UIControlStateNormal];
    imageButton.tag = counter;
[self.view addSubview:imageButton];
    x = x + 327;
    if (counter == 3){
        x = 30;
        y = 260;
    }
    if (counter ==6){
        x = 30;
        y = 510;
    }
}
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

-(void)showImage:(id)sender
{

int imageCounter = [sender tag];
UIButton *imageLarge = [UIButton buttonWithType:UIButtonTypeRoundedRect];

CGRect largeRect = CGRectMake(0,0, 1024, 768);
imageLarge.frame = largeRect;

[imageLarge addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[imageLarge setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%i.jpg",imageCounter]] forState:UIControlStateNormal];
imageLarge.tag = imageCounter;
[self.view addSubview:imageLarge];

}

-(void)back:(id)sender
{
[UIView beginAnimations:@"flipview" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view.superview cache:YES];

[self.view setHidden:YES];

[UIView commitAnimations];  

}

ここで何が欠けていますか?

4

1 に答える 1

1

-back:表示している画像を消したいときに呼び出されると思われる を非表示に設定self.viewします。コードから、 self.view は表示している画像のスーパービューです。したがって、ビュー全体を非表示にして、前のメニュー ビューのみを表示したままにします。

代わりに、imageView をインスタンス変数またはプロパティに格納してから、次のようにします。

imageView.alpha = 0.0; //Alpha animates, hidden doesn't

次に、必要に応じて必ずそのスーパービューから imageView を削除してください。

于 2011-07-18T18:34:02.343 に答える