Suppose you have an instance of UIView in the UIViewController class, for example:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, w1, h1)]; [self.view addSubview:view];
according to the requirement by which you set the appearance of the view, as I did here. I do not show the view when the controller loads it.
[view setHidden:YES]
Support the flag to check the visibility of the view instance. Let's say isViewVisible is my flag to check the visibility of a view. I set it to NO at the beginning ..
isHelpViewVisible = NO;
and I wrote an action method (viewClicked) here to expand and collapse the view object, give this action method 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 text fields and labels to the sub-view presentation object and also set the animation for these objects .. it will work.
source share