addSubviewアニメーション 質問する

addSubviewアニメーション 質問する

さまざまなデータを表示するメインの UIView があります。次に、次のようにサブビューを表示するボタンを配置します。

- (IBAction) buttonClicked:(id)sender
{
    UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(25,25,50,20)];
    UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(25,25,50,25)];
    newLabel.text = @"some text";
    [newView addSubview:newLabel];

    [self.view addSubview:newView];
    [newLabel release];
    [newView release];
}

newView は問題なく表示されますが、アニメーション化されず、すぐに表示されます。newView が表示されたときに、何らかのアニメーションを追加するにはどうすればよいでしょうか。ズームやスライドダウンなど。簡単なコードはありますか。

ベストアンサー1

[UIView transitionWithView:containerView duration:0.5
        options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
        animations:^ { [containerView addSubview:subview]; }
        completion:nil];

おすすめ記事