Xcode 中的故事板太慢了

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11691903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:02:51  来源:igfitidea点击:

Storyboard in Xcode is so slow

xcodeperformanceuiviewcontrollerstoryboardxcode4.4

提问by Maziyar

I have 150 UIViewController in Storyboard and scrolling between these Views is so slow. I can't zoom in and zoom out easily and it takes some serious time to do sty.

我在 Storyboard 中有 150 个 UIViewController 并且在这些视图之间滚动非常慢。我无法轻松放大和缩小,而且需要一些认真的时间来做麦粒肿。

I'm on MBPR and I installed Xcode 4.4

我在 MBPR 上,我安装了 Xcode 4.4

Spec: 2.3GHz / 16G / 256 which I think it's enough to handle such a thing.

规格:2.3GHz / 16G / 256 我认为这足以处理这样的事情。

Is there any options, settings, or tips/tricks to have so many views in storyboard and don't miss the performance.

是否有任何选项、设置或提示/技巧可以在故事板中拥有如此多的视图并且不会错过性能。

NOTE: I've done all the possible solutions (deleting cache and workspace). Didn't work. It has something to do with number of UIViewController in Storyboard.

注意:我已经完成了所有可能的解决方案(删除缓存和工作区)。没用。它与 Storyboard 中 UIViewController 的数量有关。

Thanks

谢谢

Update 2016: Just to update this question as there is a new feature in Xcode 7 that allows you to refactor the Storyboard into multiple Storyboards.

2016 年更新:只是为了更新这个问题,因为 Xcode 7 中有一个新功能,它允许您将故事板重构为多个故事板。

Refactoring Storyboardshttps://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/RefactorStoryboard.html

重构故事板https://developer.apple.com/library/ios/recipes/xcode_help-IB_storyboard/Chapters/RefactorStoryboard.html

If you search the term "refactoring storyboards" you will find good tutorials :)

如果您搜索术语“重构故事板”,您会找到很好的教程:)

采纳答案by Esqarrouth

Definitely use multiple storyboards for this. I am not aware of any limitations in using storyboards but trying to render all those UI code at one time is hard for your machine and it is also hard for developers to understand.

绝对为此使用多个故事板。我不知道使用故事板有任何限制,但尝试一次渲染所有这些 UI 代码对您的机器来说很难,对开发人员来说也很难理解。

Try to logically divine your storyboards into categories such as: "profileSB, feedSB, mapSB, messagesSB, settingsSB"

尝试从逻辑上将故事板划分为以下类别:“profileSB、feedSB、mapSB、messagesSB、settingsSB”

Here are some good tutorials on the creation of these:
http://spin.atomicobject.com/2014/02/18/ios-storyboards-xcode5/
http://www.skillmasters.net/main/xcode-using-multiple-storyboards/

这里有一些关于创建这些的很好的教程:
http: //spin.atomicobject.com/2014/02/18/ios-storyboards-xcode5/
http://www.skillmasters.net/main/xcode-using-multiple -故事板/

回答by Rufus Mall

It is considered best practice to split up storyboards into lots of different modules (each one in a separate storyboard). It will take away these performance issues you are having and also has other advantages such as making it easier to manage in general (no massive SVN conflicts etc).

将故事板分成许多不同的模块(每个模块在一个单独的故事板中)被认为是最佳实践。它将消除您遇到的这些性能问题,并且还具有其他优势,例如总体上更易于管理(没有大规模的 SVN 冲突等)。

However I had another issue which was causing storyboard lag. I had approx 25 view controller and was receiving ALOT of lag - but only when Xcode was running on an external monitor.

但是,我遇到了另一个导致故事板滞后的问题。我有大约 25 个视图控制器并且收到了很多延迟 - 但只有当 Xcode 在外部监视器上运行时。

I noticed that if I disabled "auto layout" for the storyboard, the lag would completely disappeared. I reverted this change, and then followed the following process: -Delete a ViewController -test if it still lags -if still laggy revert changes

我注意到如果我禁用故事板的“自动布局”,滞后就会完全消失。我恢复了这个更改,然后遵循以下过程:-删除一个 ViewController -测试它是否仍然滞后 -如果仍然滞后恢复更改

Eventually I found a certain ViewController which if deleted stopped all lag. I then reverted this and went through the views to see which view caused the lag. I eventually narrowed this down to a "UIButton" inside a "UIBarButtonItem". I believe I changed the "Type" property on the button, and then changed it back and the lag stopped. From SVN it seems like the frame was changed in the .storyboard file. After this point the lag never came back again.

最终我找到了一个特定的 ViewController,如果删除它会停止所有滞后。然后我恢复了这个并浏览了视图,看看是哪个视图导致了滞后。我最终将其缩小到“UIBarButtonItem”中的“UIButton”。我相信我更改了按钮上的“类型”属性,然后将其更改回来并且延迟停止了。从 SVN 看来,框架已在 .storyboard 文件中更改。在此之后,滞后再也没有回来。

TLDR: Storyboard lag is not always because you have too many items in the storyboard. I managed to get rid of a lag problem by causing Xcode to re-do some layout.

TLDR:故事板滞后并不总是因为故事板中有太多项目。我设法通过让 Xcode 重新做一些布局来摆脱滞后问题。

Hope my experience will help someone else diagnose/solve their problems. I was working for about 0.5 years before I finally got really annoyed and tried to solve the issue.

希望我的经验能帮助其他人诊断/解决他们的问题。我工作了大约 0.5 年,然后我终于真的很生气并试图解决这个问题。

回答by Eliav

150 ViewControllers in one Storyboard sounds awful lot to me. Try to minimize your flow or split into multiple storyboards if you really need so many

一个 Storyboard 中有 150 个 ViewControllers 对我来说听起来很糟糕。如果你真的需要这么多故事板,尽量减少你的流程或分成多个故事板

回答by Alex Cio

I had a UIStoryboardwith 10 or more UIViewControllersand additional ContainerViews. After layouting the views and customizing more and more, the UIStoryboardgot more and more lazy.

我有一个UIStoryboard10 个或更多UIViewControllers和额外的ContainerViews. 在布局视图和自定义越来越多之后,UIStoryboard变得越来越懒惰。

My approach was to setup the views inside single UIStoryboards. Loading the controllers is done inside my Menu, where I setup an NSArraywith all identifiers for the UIViewControllerwhich also have to be setup inside the UIStoryboard:

我的方法是在 single 中设置视图UIStoryboards。加载控制器是在我的菜单中完成的,我在其中设置了NSArray所有标识符,这些标识符UIViewController也必须在以下内容中设置UIStoryboard

enter image description here

在此处输入图片说明

When loading the menu, I loop through the NSArrayand load the UIViewControllersby identifiers from the specific UIStoryboard. This is the place where I needed to implement a switch, for the different UIStoryboards:

加载菜单时,我循环遍历NSArray并加载UIViewControllers来自特定UIStoryboard. 这是我需要为不同的实现开关的地方UIStoryboards

self.arrayVCAll = [NSMutableArray new];
for ( NSArray *array in _arrayViewControllerAll ){

    NSMutableArray *arrayTemp = [NSMutableArray new];

    for (UIViewController *vc in array ){
        NSString *strViewController = [NSString stringWithFormat:@"%@", vc];
        UIStoryboard *storyboard;

        if( [strViewController isEqualToString:@"CustomOneStoryboard"] ){
            storyboard = [UIStoryboard storyboardWithName:@"FirstVC" bundle:nil];

        } else if( [strViewController isEqualToString:@"CustomTwoStoryboard"] ){
            storyboard = [UIStoryboard storyboardWithName:@"SecondVC" bundle:nil];

        } else {
            storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        }

        UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:strViewController];

        MyNavController *nav = [[MyNavController alloc] initWithRootViewController:controller];
        [arrayTemp addObject:nav];
    }

    [self.arrayVCAll addObject:arrayTemp];
}

In my case, there was just a problem with the segues after separating the initial UINavigationControllerfrom my UIViewControllers. The segues won't push to a navigationController, if there is no initial UINavigationController. Thats why I added a UINavigationControlleron each UIViewController(of my NSArray) so the UIStoryboardSeguewill be done correctly. The UINavigationControlleralso doesn't need to be connected to a class, just include it inside the UIStoryboardand connect it to the first UIViewController.

就我而言,将初始文件UINavigationController与我的UIViewControllers. 如果没有初始 .segues 不会推送到导航控制器UINavigationController。这就是为什么我UINavigationController在每个UIViewController(我的 NSArray)上添加了一个,以便UIStoryboardSegue正确完成。该UINavigationController也不需要连接到一类,只是它包含在里面UIStoryboard,并把它连接到第一UIViewController