UITableViewController的子控件不随着滑动

我们知道有时候使用UITableViewController简单便捷,省事,但是如果我们使用了addSubview,无论是[self.view addSubview:view]还是[self.tableView addSubview:view],均会发现添加的view是会随着tabelview的滑动而滑动的。这是没有办法避免的,UITableViewController的view就是tableview。所以效果是一样的。

所以一般不建议直接使用UITableViewController而是使用UIViewController,手动添加UITableview。但是如果已经使用了,怎样固定子控件,不让其随着UITableview而滚动。原文连接http://www.cnblogs.com/fengtengfei/p/5671669.html

在上面固定子控件

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGRect frame = self.floatingView.frame;
    frame.origin.y = scrollView.contentOffset.y;
    self.floatingView.frame = frame;

    [self.view bringSubviewToFront:self.floatingView];
} 

在下面固定子控件

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGRect frame = self.floatingView.frame;
    frame.origin.y = scrollView.contentOffset.y + self.tableView.frame.size.height - self.floatingView.frame.size.height;
    self.floatingView.frame = frame;

    [self.view bringSubviewToFront:self.floatingView];
}   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值