简体   繁体   中英

unwind segue changed my UITableView bounds

I have an unwind segue, but I don't know what unwind segue will do against the views' bounds. It indeed changed my UITableView bounds. Is there a way to re-size my views in/after unwind segue?

I find out that unwind segue will not call any view will/did appear nor load anything. I am confused why my UITableView bounds changed.

I created all view and controllers with storyboard. I got a sidebar and home view, and on sidebar, there is a setting button to load a setting view exactly the same size as the sidebar view.

When home view -> slide out sidebar, I manually calculated the table view bounds, in order to show all cells:

-(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)];
}

I use a unwind segue for the setting view to go back to side bar view:

- (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);
                         }];
    }
}

I tried to set the ProjectTableView frame again in the completion block, though it print correct values, but the real size is not correct. I tried to print the UITable View bounds, seems normal, but my bottom cells cannot display. If I pull the window up, you can see them, but when release my fingers, it will go beneath the screen.

I suspect the unwind segue reset my UITable View size, but I don't know where to re-calcualate them again. The unwind segue will not invoke ViewDidAppear.

I figured it out, it is about auto layout. Disable or add enough layout will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM