我有一个故事板构建的视图与约束,看起来很好时,通过IB加载。当我试图从代码中加载相同的视图时,视图看起来被正确地放置在视图中,但是我的所有约束都关闭了,并且在编辑时看不到模拟器中的更改。
这是我用来加载视图的代码-
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Pop" bundle:nil];
UIViewController *vc = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"FreshPopViewController"];
firstPopView = vc.view;
vc.view = nil;
//firstPopView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//[firstPopView setFrame:self.view.frame];
[firstPopView setFrame:self.view.bounds];
UIButton *requestButton = (UIButton*)[self.view viewWithTag:101];
[requestButton addTarget:self action:@selector(newRequestButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:firstPopView];正如您在代码中看到的,我尝试过不同的方法来设置框架,但这似乎没有什么区别。
发布于 2015-09-15 14:23:05
我能够通过在VC的视图和我的所有对象之间添加一个包含的视图来修复这个问题。我不需要在代码中编辑任何东西,只需在IB中重做对这个新视图的约束。
https://stackoverflow.com/questions/32573120
复制相似问题