Ali Hassan
Ali Hassan

Reputation: 519

Animating multiple uiviews

I have to views pannelView and contentView. Pressing a button hides pannelView and expands contentView to the full screen. I have been using this code:

    if (sender.selected==NO) {
            pannelView.hidden=YES;
            contentView.frame=CGRectMake(0, 90, 768, 434);
            sender.selected=YES;
        }
        else {
            pannelView.hidden=NO;
            contentView.frame=CGRectMake(186, 90, 580, 434);
            sender.selected=NO;
        }

It switches b/w two states without animation. What should I do to animate them to look pretty? Moreover when some other button is pressed, contentView is updated. I want this view to hide and show with animation in the time content is loading.

Upvotes: 0

Views: 76

Answers (1)

Abizern
Abizern

Reputation: 150715

Have a look at the UIView documentation and the section on block based animation.

A simple example:

CGRect newFrame;
BOOL hidePanelView;
if (sender.selected==NO) {
    hidePanelView = YES;
    newFrame = CGRectMake(0, 90, 768, 434);
    sender.selected=YES;
} else {
    hidePanelView = NO;
    newframe = CGRectMake(186, 90, 580, 434);
    sender.selected=NO;
}

[UIView animateWithDuration:0.25 animations:^{
    contentView.frame = newFrame;
    pannelView.hidden = hidePanelView;
}

Upvotes: 2

Related Questions