2

タイトルのとおり、しばらくしたらオブジェクトの 1 つが消えてほしいとネットで検索しましたが、答えやチュートリアルが見つからないので、ここから質問します。

例:

ユーザーがアプリを開きます。

ビューコントローラーが画面に表示され、ラベルが表示されます。

そのラベルは 5 秒後に消えます。

どうすればできますか?

アニメーションを使用する必要がありますか?

私はアニメーションなしでそれをすることを本当に好みます(アニメーションを作るのが簡単ならOKです)

順を追って説明してください。最初にラベルを非表示にしてから、ビュー オブジェクトを非表示にします。ビューを非表示にするのは奇妙だと思います。別のビュー コントローラーを使用できますが、それは必要ありません。時間が経つと消えるようにコーディングしたい。

ありがとう。

4

2 に答える 2

8

タイマーをセットするだけです。例えば、

//In your viewDidLoad method of your view controller
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(hideLabel) userInfo:nil repeats:NO];

//In a method called hideLabel
- (void) hideLabel
{
    self.myLabel.hidden = YES;  //This assumes that your label is a property of your view controller
}

それだけです。

于 2012-07-26T01:32:17.703 に答える
3

Start a timer like this:

[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(hideWithAnimation) userInfo:nil repeats:NO];

And then when the timer hits start an animation, which is easy enough:

- (void)hideWithAnimation {

    [UIView animateWithDuration:0.5
                          delay:0.0 
                        options:UIViewAnimationOptionTransitionCrossDissolve
                     animations:^{
                                     // Fade the label
                                     [myLabel setAlpha:0]
                                 };
                     completion:NULL];
}

Here is the documentation for UIView look for Class methods:

UIView class reference

于 2012-07-26T01:38:24.837 に答える