2023年7月14日发(作者:)
iOS开发中UIScrollView的contentOffset和contentInsetcontentOffset我们在滑动UIScrollView的时候,它的contentOffset随着滑动会⼀直变化。contentInset在UIScrollView的frame之外⼜增加的⼀块区域。MJRefrefresh的heaesh的header和footer分别怎么添加的?header:直接添加在UIScrollView上,在UIScrollView的frame之外,y值是负数(header⾼度的相反数)。footer:直接添加在UIScrollView上,在UIScrollView的frame之外,y值是正数(UIScrollView的contentSize的height)。为了显⽰出来,需要设置UIScrollView的contentInset,bottom值与footer的⾼度相等。模拟UITableView添加refresh的代码添加refresh的代码// 下拉刷新View CGFloat headerH = 50.0; UIView * refreshHeader = [[UIView alloc] initWithFrame:CGRectMake(0, -headerH, , headerH)]; [iew insertSubview:refreshHeader atIndex:0]; oundColor = [UIColor redColor]; // 上拉加载view CGFloat footerY = ; CGFloat footerH = 50.0; UIView * refreshFooter = [[UIView alloc] initWithFrame:CGRectMake(0, footerY, , footerH)]; [iew insertSubview:refreshFooter atIndex:0]; oundColor = [UIColor greenColor]; _refreshFooter = refreshFooter;
// 设置tableview的contentInset tInset = UIEdgeInsetsMake(0, 0, footerH, 0);
// 监听tableview的contenSize的变化 NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld; [iew addObserver:self forKeyPath:@"contentSize" options:options context:nil];- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ if ([keyPath isEqualToString:@"contentSize"]) { CGFloat footerY = ; CGFloat footerH = 50.0; = CGRectMake(0, footerY, , footerH); }}
发布者:admin,转转请注明出处:http://www.yc00.com/web/1689265589a226473.html
评论列表(0条)