1. 程式人生 > >scrollview滑動到某區域執行某種方法

scrollview滑動到某區域執行某種方法

off rect style bound ins 檢測 return tof 執行

在這裏通過 offset.y 檢測滑動到的區域

通過if 語句執行需要的方法

 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint offset = scrollView.contentOffset;//scrollview當前顯示區域定點相對於fram頂點的偏移量
    CGRect bounds = scrollView.bounds;//原點
    CGSize size = scrollView.contentSize;//scrollview可以滾動的區域
    UIEdgeInsets inset = scrollView.contentInset;//
scrollview的contentview的頂點相對於scrollview的位置 CGFloat currentOffset = offset.y + bounds.size.height - inset.bottom; CGFloat maximumOffset = size.height; //currentOffset與maximumOffset的值相等時,說明scrollview已經滑到底部了,即偏移量達到最大值 if (offset.y <= 0) { DLog(@"滑到頂部"); SCV.contentOffset
= CGPointMake(0, 0); return; } if (currentOffset >= maximumOffset) { DLog(@"滑到底部"); // scrollView.contentOffset = CGPointMake(0, bounds.size.height - offset.y); // return; } }

scrollview滑動到某區域執行某種方法