【发布时间】:2014-12-11 02:44:30
【问题描述】:
我已经实现了一个带有 UIView 的 UIScrollView,我在 viewDidLoad() 到设置为 UIViewControllers 视图的 UIScrollView 时添加了该 UIScrollView。当我这样做时,带有 setTranslatesAutoresizingMaskIntoConstraints(false) 的 UIView 的框架如何设置为 -101.0。这不会发生在另一个显示不同的视图上,而只会发生在这个设计相同的视图上,并使用来自 navigationController 的 pushViewController 显示。
约束是从 NIB/XIB 文件中设置的,我很困惑为什么会发生这种情况。
另外需要注意的是,发生这种情况时,无论我在哪里尝试更改 UIView 的框架,它都没有影响。
编辑: viewDidLoad() 的代码:
override func viewDidLoad(){
// call the super implementation
super.viewDidLoad();
// load our scrollview from our nib file
customScrollView = CustomScrollView.loadFromNib();
// set the resizeing mask to fill screen
customScrollView!.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
// load our uiview from our nib file
containerView = ContainerView.loadFromNib();
// we handle the constraint changes
containerView!.setTranslatesAutoresizingMaskIntoConstraints(false);
customScrollView!.addSubview(containerView!);
// intialize our refresh control
refreshControl = UIRefreshControl();
refreshControl!.tintColor = UIColor.whiteColor();
refreshControl!.addTarget(self, action: "onRefresh", forControlEvents: UIControlEvents.ValueChanged);
containerView!.addSubview(refreshControl!);
// add the view to our controller here
view = customScrollView!;
}
【问题讨论】:
-
你能分享你的 viewDidLoad 代码吗?我还会检查您的 .h 文件中是否存在您的第二个视图控制器类中缺少的任何实现。
-
我会在一秒钟内上传该代码,但请记住,这很快
-
我已经更新了帖子,视图确实加载了
-
您可能应该在标题或第一行中包含它是 Swift,我看到它已经是一个标签。这是来自类的代码不起作用还是?
-
是的,这是来自非工作类的代码,即使在不使用 pushViewController 时类似的实现也有效
标签: ios swift uiview uiscrollview