天天看點

iOS 滾動視圖,上滑隐藏,下滑顯示,某個視圖 筆記

Code

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offsetY = scrollView.contentOffset.y;
    BOOL flag = NO;
    
    if (_offsetY < offsetY) { // 需要隐藏
        flag = YES;
    }
    
    if (_button.alpha == 1  // 沒有隐藏
        && flag  // 需要隐藏
        && offsetY > 0  // 處理頂部下拉回彈
        ) {
        [UIView animateWithDuration:0.25 animations:^{
            _button.alpha = 0;
        }];
    }
    else if (_button.alpha == 0  // 已經隐藏
             && !flag   // 需要顯示
             && (scrollView.mj_footer.state == MJRefreshStateIdle // 正常狀态(重新整理狀态不)顯示
             ||  scrollView.mj_footer.state == MJRefreshStateNoMoreData // 沒有更多資料
             )) {
        [UIView animateWithDuration:0.25 animations:^{
            _button.alpha = 1;
        }];
    }
    
    _offsetY = offsetY;
}      

多種樣式的驗證碼輸入框