思い立ったが吉日!

iOSが好きです。

一瞬だけ表示して消えるModalView

一瞬だけ表示して消えるModalView

f:id:watarotten:20151023202857g:plain

ModalViewを0.5秒間だけSubViewを表示して再度閉じるアニメーションを実行することで、クイズの正誤を伝えるようなアクションができる。

  • UIButtonをBRViewControllerに接続
- (IBAction)showView:(id)sender {
    BRModalViewController* modalView = [[BRModalViewController alloc] init];
    [self presentViewController: modalView animated:YES completion:nil];
}
  • BRModalViewControllerのViewDidAppearを追記
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
    // Viewが表示されたタイミングで閉じる処理を0.5秒遅らせて実行
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [self dismissViewControllerAnimated:YES completion:nil];
    });
}