Anish
Anish

Reputation: 785

How to move/push other uiviews when inserting a new uiview

I have a button and on click event of it i want to insert a UIView. I know how to insert a UIView however i am not able to push/move other UIView's that are below it so that i can accommodate the added UIView.

I have already looked at this link but it does not serve my purpose

Any suggestions?

Upvotes: 0

Views: 351

Answers (1)

yoeriboven
yoeriboven

Reputation: 3571

In the method of the button create the new view and add it as a subview. Set the frame.origin.x to 0 minus the width of the view (if you want it to push from the left) so it is not visible and change that value to where you want it to be inside [UIView animateWithDuration:animations:].

[UIView animateWithDuration:1.0 animations:^(void){
    [newView setFrame:({
        CGRect frame = newView.frame;
        frame.origin.x = 150; // If you want it to start at x = 150
        frame;
    })];

    // If you want to move other views too, just add them in this block
}];

If you don't get what I'm doing to set the frame, check out the first tip in this post.

Upvotes: 1

Related Questions