Iphone: expand and collapse UIView programmatically

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

In this expandable / resettable view, a text box and tables will appear that should appear and disappear with this view

+4
source share
4 answers

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.

+12
source

Replaces the following from above:

 [UIView beginAnimations:@"animationOff" context:NULL]; [UIView setAnimationDuration:1.3f]; [view setFrame:CGRectMake(x, y, w1, h1)]; [UIView commitAnimations]; 

With a new way to create animations:

 [UIView animateWithDuration:1.3f animations:^{ self.frame = CGRectMake( x1, x2, w1, h1); } completion:^(BOOL finished) { // this gives us a nice callback when it finishes the animation :) }]; 
+3
source

To resize / position a UIView in its parent object, just change its frame property:

 CGRect newFrame = myView.frame; newFrame.origin.x = newX; newFrame.origin.y = newY; newFrame.size.width = newWidth; newFrame.size.height = newHeight; myView.frame = newFrame; 
+1
source

You can try this

 CGRect frame = [currentView frame]; frame.size.width = 999;//Some value frame.size.height = 444;//some value [currentView setFrame:frame]; 
You can follow this whenever you want to increase / decrease view size
0
source

Source: https://habr.com/ru/post/1341766/


All Articles