Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am very new to iPhone/iPad development. can you please help me create this programmatically. I want to expand/collapse a UIView programmatically.

This expandable/collapsable view will have some text field and lables which should appear and disappear with that view

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
907 views
Welcome To Ask or Share your Answers For Others

1 Answer

Suppose you have a UIView instance in the UIViewController class like this:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, w1, h1)];
[self.view addSubview:view];

based on the requirement you set the view visibility as I did here .. I am not displaying the view when the controller is loading it's view ..

[view setHidden:YES];

Maintain a flag to check the visibility of the view instance .. lets say isViewVisible is my flag to check the visibility of the view .. I set it to NO in the begning ..

isHelpViewVisible = NO;

and I wrote an action method (viewClicked) here to expand and to collapse the view object , give this action method to a button instance and it will work.

- (void)viewClicked:(id)sender {

    if (!isViewVisible) {
        isViewVisible = YES;
        [view setHidden:NO];
        [UIView beginAnimations:@"animationOff" context:NULL]; 
        [UIView setAnimationDuration:1.3f];
        [view setFrame:CGRectMake(x, y, w1, h1)];
        [UIView commitAnimations];
    } else {
        isViewVisible = NO;
        [view setHidden:NO];
        [UIView beginAnimations:@"animationOff" context:NULL]; 
        [UIView setAnimationDuration:1.3f];
        [view setFrame:CGRectMake(x, y, width, hight)];
        [UIView commitAnimations];
    }

}

and add the textfields and labels objects to the view object as subviews and set the animation to those objects as well .. it will work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...