iOS 实现悬浮跟手滚动效果

思路: 透视图不是放在tableView上面,而是放在控制器的view面,当tablView滚动的时候

头视图就跟着tablView滚动,(通过记录上次偏移量和当前偏移量来实现, tableView滚动多少,头视图就滚动多少),然后限制一下头视图的两个边界位置即可,通过MIN和MAX实现,同时,为了实现性能的优化,在超出临界值之后,就不再设置frame

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y > self.lastOffset && CGRectGetMinY(self.headerView.frame) <= 50) {
        self.lastOffset = scrollView.contentOffset.y;
        return;
    }
    if (scrollView.contentOffset.y < self.lastOffset && CGRectGetMinY(self.headerView.frame) >= 100) {
        self.lastOffset = scrollView.contentOffset.y;
        return;
    }
    CGRect rect = self.headerView.frame;
    CGPoint orign = rect.origin;
    orign.y -=(scrollView.contentOffset.y - self.lastOffset);
    orign.y = MIN(100, MAX(50, orign.y));
    rect.origin = orign;
    self.headerView.frame = rect;
    self.lastOffset = scrollView.contentOffset.y;
}
相关推荐
万兴丶2 小时前
Unnity IOS安卓启动黑屏加图(底图+Logo gif也行)
android·unity·ios
2401_852403555 小时前
探索iPhone一键删除重复照片的方法
ios·iphone
pf_data1 天前
手机换新,怎么把旧iPhone手机数据传输至新iPhone16手机
ios·智能手机·iphone
键盘敲没电1 天前
【iOS】KVC
ios·objective-c·xcode
吾吾伊伊,野鸭惊啼1 天前
2024最新!!!iOS高级面试题,全!(二)
ios
吾吾伊伊,野鸭惊啼1 天前
2024最新!!!iOS高级面试题,全!(一)
ios
不会敲代码的VanGogh2 天前
【iOS】——应用启动流程
macos·ios·objective-c·cocoa
Swift社区2 天前
Apple 新品发布会亮点有哪些 | Swift 周报 issue 61
ios·swiftui·swift
逻辑克2 天前
使用 MultipeerConnectivity 在 iOS 中实现近场无线数据传输
ios
dnekmihfbnmv2 天前
好用的电容笔有哪些推荐一下?年度最值得推荐五款电容笔分享!
ios·电脑·ipad·平板