禁用tableHeaderView(不要与节头混淆)滚动
是否有可能禁用滚动tableHeaderView (不要与节头混淆) 。现在,每当我滚动表,查看tableHeaderView也滚动。
我在做什么:
- 我有一个从UITableViewController分类的类。
- 在故事板中,我正在使用静态表格视图。
- 表格样式是分组的,我添加了8个分区,每个分区都有一行。
- 在第一部分的顶部,添加了一个视图tableHeaderView。
当我滚动表格时,我想禁用标题“Profile”的滚动视图。
PS:我知道这是可以实现的,如果我从UIViewController而不是UITableViewController我的类。 但我不想UIViewController,因为我正在使用storyboard来devise静态单元格,如果我使用UIViewController而不是UITableViewController,那么编译器将会抛出一个警告:“静态表格视图只有embedded到UITableViewController实例中才有效”
请让我知道哪个是最好的方法来实现this.Is可能禁用滚动tableHeader使用我目前的做法,或者我需要使用UIViewController代替。
只需使用嵌套segue与包含标题视图和容器视图的父级UIViewController
。 将你的UITableViewController
embedded到容器视图中。 在这个答案更具体的步骤。
如果你想在UITableViewController
一切,你可以插入你自己的子视图做这样的事情:
- (void)viewDidLoad { [super viewDidLoad]; self.header = [[UIView alloc] init]; self.header.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 44); self.header.backgroundColor = [UIColor greenColor]; [self.tableView addSubview:self.header]; self.tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0); }
然后在scrollViewDidScroll
和好友中操作视图的位置:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { self.header.transform = CGAffineTransformMakeTranslation(0, self.tableView.contentOffset.y); }
我说“和朋友”,因为你需要照顾的angular落情况像scrollViewDidScrollToTop:
scrollViewDidScroll
在滚动的每个显示周期中被调用,所以这样做看起来完美无瑕。
蒂莫西·穆斯现身。 这里是iOS8的必要变化。
MonoTouch(C#)
// create the fixed header view headerView = new UIView() { Frame = new RectangleF(0,0,this.View.Frame.Width,44), AutoresizingMask = UIViewAutoresizing.FlexibleWidth, BackgroundColor = UIColor.DarkGray }; // make it the top most layer headerView.Layer.ZPosition = 1.0f; // add directly to tableview, do not use TableViewHeader TableView.AddSubview(headerView); // TableView will start at the bottom of the nav bar this.EdgesForExtendedLayout = UIRectEdge.None; // move the content down the size of the header view TableView.ContentInset = new UIEdgeInsets(headerView.Bounds.Height,0,0,0); ..... [Export("scrollViewDidScroll:")] public virtual void Scrolled(UIScrollView scrollView) { // Keeps header fixed, this is called in the displayLink layer so it wont skip. if(headerView!=null) headerView.Transform = CGAffineTransform.MakeTranslation(0, TableView.ContentOffset.Y); } [Export ("scrollViewDidScrollToTop:")] public virtual void ScrolledToTop (UIScrollView scrollView) { // Keeps header fixed, this is called in the displayLink layer so it wont skip. if(headerView!=null) headerView.Transform = CGAffineTransform.MakeTranslation(0, TableView.ContentOffset.Y); }