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

Categories

0 votes
946 views
in Technique[技术] by (71.8m points)

xcode - iphone: expand and collapse a UIView programmatically

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...