OGeek|极客世界-中国程序员成长平台

标题: ios - 设计离屏 subview 的 Storyboard [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:29
标题: ios - 设计离屏 subview 的 Storyboard

我想使用 Storyboards 为 slider 设计内容,而设计离屏内容的一种简单方法似乎是使用 childViewController。所以我已经这样做了

myViewController = [[UIStoryboard storyboardWithName"ipad" bundle:NULL] instantiateViewControllerWithIdentifier"keyPadOffScreen"];

[self addChildViewController:myViewController];
[myViewController didMoveToParentViewController:self];
newView = myViewController.view;
[self.view addSubview:newView];

这会将整个 View Controller 添加到我的 Root View 之上。问题是,我只想显示其中一个 subview ,而不是整个 View 。只要我知道如何添加 Root View ,我就可以处理动画。我试过这个只是添加 subview (sliderView 是我想要的 subview 的名称)而不是整个 View ,但这什么也没做

newView = myViewController.sliderView;
[self.view addSubview:newView];

我应该使用不同的策略吗?

编辑:这确实有效,但似乎很愚蠢 - 将 View 大小设置为 subview 的大小。

  newView.frame = CGRectMake(newView.frame.origin.x, newView.frame.origin.y, newView.frame.size.width, **myViewController.sliderView.frame.size.height**);



Best Answer-推荐答案


仅仅为了一个 View ,它似乎有点矫枉过正。一旦你开始做很多自定义 View /动画/过渡的东西,它通常更容易在代码中实现,或者至少对我来说是这样,因为我已经这样做了很长时间了。

但也许您想坚持使用 Storyboard。我尊重。如果你有几个开发人员在做这件事,那么在你设置 UI 的方式上保持一定的一致性是很重要的。

与其将其保存在单独的 View Controller 中并在需要时添加它以在屏幕上显示动画效果,只需将其添加到现有 View Controller 中并将其设置为隐藏,或者在 IB 中将其 alpha 设置为 0.0。然后您的动画可以撤消它并使其可见。

关于ios - 设计离屏 subview 的 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20694389/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4