在UINavigationController推送和弹出后,UIScrollView子项跳转 [英] UIScrollView child jumping after UINavigationController push and pop

查看:120
本文介绍了在UINavigationController推送和弹出后,UIScrollView子项跳转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的iPad应用程序上有一个 UIScrollView ,只有一个子视图(它本身就是所有控件的父视图)。滚动一切正常。旋转工作正常(整个视图适合纵向,在风景上滚动)。一旦在 UINavigationController 上推新屏幕,然后回来就打破它。

So I have a UIScrollView on my iPad app with a single child view (which itself is parent to all the controls). The scrolling all works fine on it. Rotating works fine (the whole view fits in portrait, scrolls on landscape). Once pushing a new screen on the UINavigationController, and then coming back breaks it.

看起来好像是框架相对于滚动位置,scrollview的子项已经向上移动,但是scrollview一直保持在底部(整个子视图向上移动)。

It looks as if the frame of the scrollview's child has moved up, relative to the scroll position, but the scrollview has remained at the bottom (the entire child view has shifted upwards).

我已经尝试在故事板中与约束作斗争,几个小时,并且无法解决可能导致这种情况的原因。

I've tried fighting the Constraints in storyboard, literally for hours, and cannot work out what could be causing this.


推荐答案

我在滚动视图和自动布局方面遇到了同样的问题(iOS 6 - 不起作用,iOS 7 - 工作正常),当然这不是完美的解决方案,但似乎有效。希望它能帮到你:

I had the same problem with scroll view and auto layouts (iOS 6 - doesn't work, iOS 7 - works fine), of course this is not perfect solution, but seems like it works. Hope it will help you:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self performSelector:@selector(content) withObject:nil afterDelay:0.0];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    offset = self.scrollView.contentOffset;
}

- (void)viewDidDisappear:(BOOL)animated
{
   [super viewDidDisappear:animated];

   self.scrollView.contentOffset = CGPointZero;
}

- (void)content
{
    [self.scrollView setContentOffset:offset animated:NO];
}

这篇关于在UINavigationController推送和弹出后,UIScrollView子项跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆