0

一个 UISCrollview 发生了一些奇怪的事情。

我的方案是 MainView -> ScrollView -> ViewScrollView

- (void)viewDidAppear:(BOOL)animated{

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    if (appDelegate.first_time ) {
        NSLog(@"First time.We need to feed sqlite.");

        [self showSplash];

        appDelegate.first_time = false;
    }

    _scrollView.contentSize = CGSizeMake(768*2, 870);
    [_scrollView setScrollEnabled:YES];

    ... other stuff
}

应用程序加载并且滚动视图完美运行。完全没有问题。

我遇到的唯一问题是应用程序第一次运行。它需要下载一些大文件来提供 ipad 的 sqlite 数据库,它可能非常慢,(它必须下载大约 10Mb)所以我创建了一个启动屏幕,显示需要多长时间,下载了多少等。 ..

如代码所示,我将其加载为 [self showSplash];

#pragma mark splash screen
- (void)showSplash {

    NSLog(@"showSplash");

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    modalSplashScreenViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"modalSplashScreenViewController"];
    sfvc.delegate = (id)self;
    [sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:sfvc animated:NO completion:nil];
}

它按原样显示启动画面并开始下载

- (void)viewDidAppear:(BOOL)animated{

    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.dimBackground = YES;
    hud.labelText = @"Loading";
    hud.detailsLabelText = @"updating data";
    hud.delegate = self;

    [hud showWhileExecuting:@selector(feed_it) onTarget:self withObject:nil animated:YES];
}
- (void)feed_it{
    // feeds sqlite
    // when has finished closes the view.
    [self dismissViewControllerAnimated:YES completion:nil];
}

隐藏启动画面后, UIScrollView 不会滚动。

这是我从“ViewDidAppear”末尾得到的日志文件,在 splashScreen 关闭后调用。(如果我第二次运行该应用程序而没有出现启动画面,则完全相同)

_viewScrollView frame width  1536.000000 frame origin.x 0.000000
_viewScrollView frame height 870.000000 frame origin.y 0.000000
_scrollview frame width  768.000000 frame origin.x 0.000000
_scrollview frame height 870.000000 frame origin.y 45.000000
_scrollView.contentSize.width 1536.000000 height:870.000000
_scrollView.contentOffset.x 0.000000 y:0.000000
_scrollView.bounds.size.width 768.000000 height 870.000000 
_scrollView.intrinsicContentSize.width -1.000000
_scrollView.contentSize.width 1536.000000 height:870.000000

不加载启动画面就可以工作,加载后就不行。

有人知道发生了什么吗?

4

1 回答 1

1

最后我解决了。这是我在 XCode 中见过的最奇怪的事情。

我在这个应用程序中有很多使用故事板转场的模态视图,当我返回主视图时,滚动视图工作得很好,所以我尝试用转场而不是编码来显示启动画面,而且,魔法!有效!

深入研究代码,我发现了两者之间的独特差异

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    modalSplashScreenViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"modalSplashScreenViewController"];
    sfvc.delegate = (id)self;
    [sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:sfvc animated:NO completion:nil];

并且segue方法是:modalPresentationStyle,

在 IDE 上,我选择了“Page Sheet”,在代码中我有 UIModalPresentationFullScreen。

因此,将所有代码恢复到我在这里提出问题的那一刻,并更改

[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];

为了

[sfvc setModalPresentationStyle:UIModalPresentationPageSheet];

滚动视图再次完美运行。

谁能解释我为什么会这样?也许是一个错误?

于 2013-05-31T00:26:20.277 回答