2014年9月29日 星期一

UIScrollView 滑動到最下方增加資料 scrollView scroll to the end add data


在UITableView與UICollection的時候可以透過滑動到最下面的時候去更新資料

透過UIScrollView的delegate來實現


- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
    if (bottomEdge >= scrollView.contentSize.height)  {
        //更新資料的動作
        [self callApi];
        //呼叫loading畫面
        [UIView animateWithDuration:0.5
                              delay:0
                            options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
                             self.endLoadingView.hidden = NO;
                             CGRect frame = self.endLoadingView.frame;
                             frame.origin.y += CGRectGetHeight(frame);
                             self.endLoadingView.frame = frame;
                             frame.origin.y -= CGRectGetHeight(frame);
                             self.endLoadingView.frame = frame;
 
                         }
                         completion:NULL];
        
        
        
    }
}

沒有留言:

張貼留言