scrollViewDidEndScrollingAnimation和scrollViewDidEndDecelerating的區別

#pragma mark - 監聽
/**
  *  點擊了頂部的標題按鈕
  */
- ( void )titleClick:(XMGTitleButton *)titleButton
{
     // 修改按鈕狀態
     self .clickedTitleButton.selected =  NO ;
     titleButton.selected =  YES ;
     self .clickedTitleButton = titleButton;
     
     // 移除底部下劃線
     [ UIView  animateWithDuration:0.25 animations:^{
         self .titleUnderlineView.width = titleButton.titleLabel.width;
         self .titleUnderlineView.centerX = titleButton.centerX;
     }];
     
     // 讓scrollView滾動到對應的位置(不要去修改contentOffset的y值)
     CGPoint offset =  self .scrollView.contentOffset;
     offset.x = titleButton.tag *  self .scrollView.width;
     [ self .scrollView setContentOffset:offset animated: YES ];
   //不是人爲拖拽scrollView致使滾動完畢,會調用scrollViewDidEndScrollingAnimation這個方法
}
 
#pragma mark - <UIScrollViewDelegate>
/**
  *  滾動完畢就會調用(若是不是人爲拖拽scrollView致使滾動完畢,纔會調用這個方法
  */
- ( void )scrollViewDidEndScrollingAnimation:( UIScrollView  *)scrollView
{
     int  index = scrollView.contentOffset.x / scrollView.width;
     UIViewController  *willShowChildVc =  self .childViewControllers[index];
     
     // 若是這個子控制器的view已經添加過了,就直接返回
     if  (willShowChildVc.isViewLoaded)  return ;
     
     // 添加子控制器的view
     willShowChildVc.view.frame = scrollView.bounds;
     [scrollView addSubview:willShowChildVc.view];
}
 
/**
  *  滾動完畢就會調用(若是是人爲拖拽scrollView致使滾動完畢,纔會調用這個方法
  */
- ( void )scrollViewDidEndDecelerating:( UIScrollView  *)scrollView
{
     int  index = scrollView.contentOffset.x / scrollView.width;
     // 點擊對應的按鈕
     [ self  titleClick: self .titleButtons[index]];
     
     // 添加子控制器的view
     [ self  scrollViewDidEndScrollingAnimation:scrollView];
}
相關文章
相關標籤/搜索