문제

Every time I click on my UISegementedControl it snaps back to its original frame. I can see it barely through my translucent toolbar. I have a UIViewController with a UITableView, and UIToolBar like this: my view controller

There is a UISegmentedControl hidden just below the table view, behind the toolbar: storyboard layout setup

The Filter button calls the 'onFilterButtonPressed' method

- (IBAction)onFilterButtonPressed:(id)sender
{
    if(self.filterBar.hidden){
        [self showFilterBar];
    } else {
        [self hideFilterBar];
    }
}

- (void)hideFilterBar
{
    CGRect filterBarFrame = CGRectMake(0, self.view.frame.size.height+(self.filterBar.frame.size.height+1), self.filterBar.frame.size.width, self.filterBar.frame.size.height);
    CGRect tableViewFrame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y,self.tableView.frame.size.width, self.tableView.frame.size.height+(self.filterBar.frame.size.height+1));

    [UIView animateWithDuration:0.3 animations:^{
        [self.filterBar setFrame:filterBarFrame];
        [self.tableView setFrame:tableViewFrame];
    } completion:^(BOOL finished) {
        self.filterBar.hidden = YES;
    }];
}

- (void)showFilterBar
{
    CGRect filterBarFrame = CGRectMake(0, self.view.frame.size.height-(self.filterBar.frame.size.height+1), self.filterBar.frame.size.width, self.filterBar.frame.size.height);
    CGRect tableViewFrame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y,self.tableView.frame.size.width, self.tableView.frame.size.height-(self.filterBar.frame.size.height+1));

    self.filterBar.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        [self.tableView setFrame:tableViewFrame];
        [self.filterBar setFrame:filterBarFrame];
    }];

}
도움이 되었습니까?

해결책

This is because of auto layout. With that turned on (which it is by default), you should do any positioning or resizing of views by modifying constraints, not setting frames.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top