2012-03-12 19 views
0

私が実現したいのは、ビューに1秒間画像を表示

ボタンをタッチすると、画像が1秒間ビューに表示され、画像が消えます。

私はNSTimerは役立ちますが、私は、右のコードの書き方を知らない...あなたの助けを必要とし、感謝していることを知っています。

- (IBAction)bodytouched:(id)sender { 
bodytouchedimage.hidden = NO; 
    bodytouchedimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beated.jpg"]]; 
    bodytouchedimage.userInteractionEnabled = YES; 
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showPictures:) userInfo:nil repeats:NO]; 
} 


- (void)showPictures:(NSTimer *)timer {  
bodytouchedimage.hidden = YES; 
} 
+0

hidePicturesメソッドを呼び出しますNSTimerを追加しているためにすべき?それはうまくいくように見えます。それはあなたのためではありませんか? – mattjgalloway

+0

今、それが動作します。 「:」の後に@selector!!私はところで、あなたが見逃しているあなたに感謝し、接続を行う、.xibファイルのビューにUIImageViewを入れてそれのために画像を選び、ライン3それが動作 – iPhrog

答えて

3

あなたは、あなたがボタンをタッチするとshowPictures関数を呼び出した後、showPicturesメソッド内であなたがそのことについては動作しませんどのような1秒後

- (void)showPictures 
{ 
    bodytouchedimage.hidden = NO; 
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(hidePictures) userInfo:nil repeats:NO]; 
} 

- (void)hidePictures 
{ 
    bodytouchedimage.hidden = YES; 
} 
+1

うん!それはまさに私が最後にしたものです。ありがとう – iPhrog

1

むしろNSTimerを使用するよりも、単に、このように画像を隠すために、あなたのメソッドを呼び出すことが容易になるだろう:

- (IBAction)bodytouched:(id)sender { 
bodytouchedimage.hidden = NO; 
    bodytouchedimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"beated.jpg"]]; 
    bodytouchedimage.userInteractionEnabled = YES; 
    [self performSelector:@selector(hidePicture) withObject:nil afterDelay:1]; 
} 


- (void)hidePicture {  
bodytouchedimage.hidden = YES; 
} 

performSelector:withObject:afterDelay:NSObjectクラスのメソッドです。

+0

のコードを削除します(hidePicture :) – iPhrog

関連する問題