简体   繁体   中英

How to stop a UIView from scrolling with tableview?

I have a UITableViewController and I put a UIView right under the navigation item and above the actual table. The problem that I have is that the view scrolls with the tableview.

How would I get it to behave exactly like the nav bar, and have the items in the tableview scroll behind it.

Rather than having the view scroll, it should remain in its position and have everything go behind it. Sorry for reiterating, but I've found thats necessary sometimes.

在此处输入图片说明

The view you're placing above the cell in the storyboard becomes the table view's tableHeaderView .

You can make the header view appear fixed by resetting its frame.origin to the table view's bounds.origin every time the table view lays out its subviews:

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    UIView *header = self.tableView.tableHeaderView;
    CGRect frame = header.frame;
    frame.origin = self.tableView.bounds.origin;
    header.frame = frame;
}

Result:

固定表视图标题的演示

Assuming you don't want the map view to move then you could set its user interaction to false.

Alternatively you could set the header of your tableView (if you only have one section) to the map view.

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