Krunal
Krunal

Reputation: 6490

UIVIew Resizes on UIScrollView Scroll

I am developing app in which my parent view is UIScrollView and child views are UIView and UIButton.

When i click on UIButton i am increasing the height of UIView programatically(this works fine)

But after when i scroll my scrollView my UIView resizes to its original height, i also tried changing height of UIView in scrollViewDidScroll method but it doesn't work :(

Please help..

Here is my code snippet:

- (IBAction)ButtonClicked:(id)sender {

    [UIView animateWithDuration:0.8f delay:0.0f options:UIViewAnimationOptionTransitionNone animations: ^{
        MyView.frame = CGRectMake(8, 243, 304, 400);
    } completion:nil];
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    MyView.frame = CGRectMake(8, 243, 304, 400);  
}

Thanks in advance !!

Upvotes: 1

Views: 575

Answers (1)

Alex
Alex

Reputation: 616

You should connect left(top, width or height) constraints as IBOutlets and should change them.

Because view is re-layouted with auto layout constraints when you scroll scrollview.

So

myViewLeftConstraint.constant = 8
myViewTopConstraint.constant = 243
myViewWidthConstraint.constant = 304
myViewHeightConstraint.constant = 400

like this.

Upvotes: 2

Related Questions