unwind segue 改变了我的 UITableView 边界
unwind segue changed my UITableView bounds
我有一个 unwind segue,但我不知道 unwind segue 会对视图的边界做些什么。它确实改变了我的 UITableView 边界。有没有办法调整我的视图 in/after unwind segue?
我发现 unwind segue 不会调用任何视图 will/did 出现也不会加载任何内容。我很困惑为什么我的 UITableView 边界改变了。
我使用故事板创建了所有视图和控制器。我有一个侧边栏和主页视图,在侧边栏上,有一个设置按钮可以加载与侧边栏视图完全相同大小的设置视图。
当主视图->滑出侧边栏时,我手动计算了table视图边界,以便显示所有单元格:
-(void) viewDidAppear {
[super viewDidAppear];
[self.ProjectTableView setFrame:CGRectMake(self.view.bounds.origin.x,
self.SideBarHeaderBGImageView.bounds.size.height + self.HomeButton.bounds.size.height + self.AlertButton.bounds.size.height,
self.view.bounds.size.width,
self.view.bounds.size.height - self.SideBarHeaderBGImageView.bounds.size.height - self.HomeButton.bounds.size.height - self.AlertButton.bounds.size.height)];
}
我在设置视图中使用了 unwind segue 来返回侧边栏视图:
- (IBAction)unwindToSideBar:(UIStoryboardSegue *)unwindSegue
{
// get the unwind view controllers
#ifdef DEBUG
NSLog(@"%@ triggered unwind segue to SideBar", unwindSegue.sourceViewController);
#endif
if ([unwindSegue.sourceViewController isKindOfClass:[UserSettingViewController class]]) {
__block UIViewController *UserSettingVC = unwindSegue.sourceViewController;
//setup animateFrame
CGRect animateFrame = CGRectMake(-UserSettingVC.view.frame.size.width,
0,
UserSettingVC.view.frame.size.width,
UserSettingVC.view.frame.size.height);
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
UserSettingVC.view.frame = animateFrame;
UserSettingVC.view.alpha = 0.0f;
}
completion:^(BOOL finished) {
UserSettingVC.view.alpha = 0.0f;
[UserSettingVC willMoveToParentViewController:nil];
[UserSettingVC.view removeFromSuperview];
[UserSettingVC removeFromParentViewController];
UserSettingVC = nil;
//[self resizeSubViews];
//NSLog(@"self view height %f, bg %f, home %f, alert %f, proj y %f", self.view.bounds.size.height, self.SideBarHeaderBGImageView.bounds.size.height, self.HomeButton.bounds.size.height, self.AlertButton.bounds.size.height, self.SideBarHeaderBGImageView.bounds.size.height + self.HomeButton.bounds.size.height + self.AlertButton.bounds.size.height);
//NSLog(@"proj height %f", self.view.bounds.size.height - self.SideBarHeaderBGImageView.bounds.size.height - self.HomeButton.bounds.size.height - self.AlertButton.bounds.size.height);
}];
}
}
我尝试在完成块中再次设置 ProjectTableView 框架,虽然它打印了正确的值,但实际大小不正确。
我尝试打印 UITable View 边界,看起来很正常,但我的底部单元格无法显示。如果我把 window 向上拉,你可以看到它们,但是当我松开手指时,它会进入屏幕下方。
我怀疑 unwind segue 重置了我的 UITable View 大小,但我不知道在哪里重新计算它们。 unwind segue 不会调用 ViewDidAppear。
我明白了,它是关于自动布局的。禁用或添加足够的布局将起作用。
我有一个 unwind segue,但我不知道 unwind segue 会对视图的边界做些什么。它确实改变了我的 UITableView 边界。有没有办法调整我的视图 in/after unwind segue?
我发现 unwind segue 不会调用任何视图 will/did 出现也不会加载任何内容。我很困惑为什么我的 UITableView 边界改变了。
我使用故事板创建了所有视图和控制器。我有一个侧边栏和主页视图,在侧边栏上,有一个设置按钮可以加载与侧边栏视图完全相同大小的设置视图。
当主视图->滑出侧边栏时,我手动计算了table视图边界,以便显示所有单元格:
-(void) viewDidAppear {
[super viewDidAppear];
[self.ProjectTableView setFrame:CGRectMake(self.view.bounds.origin.x,
self.SideBarHeaderBGImageView.bounds.size.height + self.HomeButton.bounds.size.height + self.AlertButton.bounds.size.height,
self.view.bounds.size.width,
self.view.bounds.size.height - self.SideBarHeaderBGImageView.bounds.size.height - self.HomeButton.bounds.size.height - self.AlertButton.bounds.size.height)];
}
我在设置视图中使用了 unwind segue 来返回侧边栏视图:
- (IBAction)unwindToSideBar:(UIStoryboardSegue *)unwindSegue
{
// get the unwind view controllers
#ifdef DEBUG
NSLog(@"%@ triggered unwind segue to SideBar", unwindSegue.sourceViewController);
#endif
if ([unwindSegue.sourceViewController isKindOfClass:[UserSettingViewController class]]) {
__block UIViewController *UserSettingVC = unwindSegue.sourceViewController;
//setup animateFrame
CGRect animateFrame = CGRectMake(-UserSettingVC.view.frame.size.width,
0,
UserSettingVC.view.frame.size.width,
UserSettingVC.view.frame.size.height);
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
UserSettingVC.view.frame = animateFrame;
UserSettingVC.view.alpha = 0.0f;
}
completion:^(BOOL finished) {
UserSettingVC.view.alpha = 0.0f;
[UserSettingVC willMoveToParentViewController:nil];
[UserSettingVC.view removeFromSuperview];
[UserSettingVC removeFromParentViewController];
UserSettingVC = nil;
//[self resizeSubViews];
//NSLog(@"self view height %f, bg %f, home %f, alert %f, proj y %f", self.view.bounds.size.height, self.SideBarHeaderBGImageView.bounds.size.height, self.HomeButton.bounds.size.height, self.AlertButton.bounds.size.height, self.SideBarHeaderBGImageView.bounds.size.height + self.HomeButton.bounds.size.height + self.AlertButton.bounds.size.height);
//NSLog(@"proj height %f", self.view.bounds.size.height - self.SideBarHeaderBGImageView.bounds.size.height - self.HomeButton.bounds.size.height - self.AlertButton.bounds.size.height);
}];
}
}
我尝试在完成块中再次设置 ProjectTableView 框架,虽然它打印了正确的值,但实际大小不正确。 我尝试打印 UITable View 边界,看起来很正常,但我的底部单元格无法显示。如果我把 window 向上拉,你可以看到它们,但是当我松开手指时,它会进入屏幕下方。
我怀疑 unwind segue 重置了我的 UITable View 大小,但我不知道在哪里重新计算它们。 unwind segue 不会调用 ViewDidAppear。
我明白了,它是关于自动布局的。禁用或添加足够的布局将起作用。