Lalit Paliwal
Lalit Paliwal

Reputation: 723

Expanding and Shrinking UIView in iPhone

I am working on an iPhone games like application, where I have to ask one question and corresponding answers on UIButoons. When user presses any button I show right and wrong image based on chosen answer. I create answer view by following code and attach it to main view:

-(void)ShowOutputImageAsAnswerView:(BOOL)correct
{   

    viewTimer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(RemoveSubViewFromMainView) userInfo:nil repeats:YES];
    UIView  *viewOutput = [[UIView alloc]initWithFrame:CGRectMake(200, 100, 80, 80)];
    viewOutput.tag  = 400;
    viewOutput.backgroundColor = [UIColor clearColor];
    UIImageView *imgAns = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
    if (correct)
    {
        imgAns.image = [UIImage imageNamed:@"correct_icon.png"];
    }
    else
    {
        imgAns.image = [UIImage imageNamed:@"wrong_icon.png"];
    }   
    [viewOutput addSubview:imgAns];
    [self.view addSubview:viewOutput];
    [self.view bringSubviewToFront:viewOutput];

    [imgAns release];
    [viewOutput release];   

}

I have to show this answer view in the animated form. And this animation will start from its 0 pixel to 80 pixel. Means expanding and shrinking view.

How can it be implemented? Can it directly be used with imgAns?

Upvotes: 1

Views: 1097

Answers (1)

Rui Peres
Rui Peres

Reputation: 25927

You create an animation by doing something like this:

myView.frame=CGRectMake(myView.frame.origin.x,myView.frame.origin.y,0.,0.);

[UIView animateWithDuration:1
                     animations:^{
                        //put your animation here
                        myView.frame=CGRectMake(myView.frame.origin.x,myView.frame.origin.y,80.,80-);    
                     }];

I haven't tried this code, but it should give you a good perspective of how to do it.

Upvotes: 1

Related Questions