开发者

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 s开发者_如何学Gotart from its 0 pixel to 80 pixel. Means expanding and shrinking view.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜