日々精進

新しく学んだことを書き留めていきます

hidden = NOとアニメーションを一緒にやるとアニメーションがキャンセルされる

hiddenはアニメーションできないプロパティなので、以下のようなコードを書くとアニメーションがキャンセルされる。

    self.view.hidden = NO;
    [UIView animateWithDuration:0.2 animations:^{
        self.view.frame = CGRectMake(0, 0, 100, 100);
    }];

アニメーションさせるにはhiddenでなくalphaを使ってviewを非表示にすればいい。

    self.view.alpha = 1;
    [UIView animateWithDuration:0.2 animations:^{
        self.view.frame = CGRectMake(0, 0, 100, 100);
    }];

参考:iphone - How to add animation while changing the hidden mode of a uiview? - Stack Overflow