0
votes

I'm attempting to allocate a webview with a specific frame, and then animate both its y position and height. When I do so, the webview instantly snaps to its "final" position, not animating the y, but it is animating the height.

Also, just so there's no confusion, I use UIView+Positioning (https://github.com/freak4pc/UIView-Positioning) to set my x,y,height, and width, instead of fiddling with the CGRects :)

Here is a screen capture of the animation, the issue is that the webview is instantly created at y=260/height=0px, where it should start at y=340/height=0px and transition to y=260 and height=maxHeight. y=340px is where the top and bottom split, and is where the "close" animation on the webview focuses to.

The code

    for (PageViewController * page in pages) {
        [page preFullscreen];
    }
    [UIView animateWithDuration:0.5f animations: ^() {
        for (PageViewController * page in pages) {
            [page fullScreen];
        }
    }];

...

- (void)preFullscreen {
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 340.0f, 320.0f, 0.0f)];
    _webView.delegate = self;
    _webView.scrollView.bounces = NO;
    _webView.scrollView.scrollEnabled = NO;
    _webView.scalesPageToFit = YES;
    _webView.backgroundColor = [UIColor whiteColor];
    [_scrollView addSubview:_webView];
    [_webView loadHTMLString:[entry storyHTML] baseURL:nil];
}

- (void)fullScreen {
    _darkOverlayview.alpha = 0.0f;
    _webView.y=260.0f;
    _webView.height = [[UIScreen mainScreen] bounds].size.height - 260.0f;
    _scrollView.delegate = hsVC;
    _textareaView.hidden = YES;
    _frontImage.height = 260.0f;
    self.view.height = [[UIScreen mainScreen] bounds].size.height;
    _scrollView.height = [[UIScreen mainScreen] bounds].size.height;
}
1

1 Answers

2
votes

I think the problem is precisely that you are using the UIView+Positioning additions? Internally it ends up setting the frame multiple times within the animation block, so the start position is lost. Use the regular setFrame: to set the entire frame once per view in the animation block.

As for animating the UIWebView, I also recommend setting it to full height in preFullscreen (so that it's below the bottom edge of the screen) and only animating the y coordinate. In my experience resizing webviews during animation can be problematic since the web content is also resized.