You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
6.4 KiB

/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2020 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// UITableView+QMUI.h
// qmui
//
// Created by QMUI Team on 15/7/20.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// cell 在当前 section 里的位置,注意判断时要用 (var & xxx) == xxx 的方式
typedef NS_OPTIONS(NSInteger, QMUITableViewCellPosition) {
QMUITableViewCellPositionNone = 0, // 默认
QMUITableViewCellPositionFirstInSection = 1 << 0,
QMUITableViewCellPositionMiddleInSection = 1 << 1,
QMUITableViewCellPositionLastInSection = 1 << 2,
QMUITableViewCellPositionSingleInSection = QMUITableViewCellPositionFirstInSection | QMUITableViewCellPositionLastInSection,
};
/**
*
* 1. UITableView QMUITableView
* 2. view indexPath cell
* 3. view sectionHeader
* 4. sectionHeader index
* 5. pinned sectionHeader index
* 6. sectionHeader pinned
* 7. cell indexPath
* 8. cell indexPath QMUITableViewCellPosition
* 9. selection
* 10.
* 11. row row Top/Middle/Bottom
* 12. searchBar tableHeaderView contentSize searchBar navigationBar contentSize
* 13. searchBar tableHeaderView
*/
@interface UITableView (QMUI)
/// 将当前tableView按照QMUI统一定义的宏来渲染外观
- (void)qmui_styledAsQMUITableView;
/**
* view tableView indexPath
*
* 使 cell addTarget indexPath
*
* @param view UIView
* @return view indexPath nil
*/
- (nullable NSIndexPath *)qmui_indexPathForRowAtView:(nullable UIView *)view;
/**
* view tableView sectionHeaderView
* @param view UIView
* @return view sectionHeaderView section -1
*/
- (NSInteger)qmui_indexForSectionHeaderAtView:(nullable UIView *)view;
/// 获取可视范围内的所有 sectionHeader 的 index
@property(nonatomic, readonly, nullable) NSArray<NSNumber *> *qmui_indexForVisibleSectionHeaders;
/// 获取正处于 pinned(悬停在顶部)状态的 sectionHeader 的序号
@property(nonatomic, readonly) NSInteger qmui_indexOfPinnedSectionHeader;
/**
* section header pinned
* @param section section
* @note header1 pinned header2 pinned header1 header2 pinned
*/
- (BOOL)qmui_isHeaderPinnedForSection:(NSInteger)section;
/// 判断当前 indexPath 的 item 是否为可视的 item
- (BOOL)qmui_cellVisibleAtIndexPath:(nullable NSIndexPath *)indexPath;
/**
* indexPathdataSource得到对应的cell在当前section中所处的位置
* @param indexPath cell所在的indexPath
* @return indexPath对应的cell在当前section中所处的位置
*/
- (QMUITableViewCellPosition)qmui_positionForRowAtIndexPath:(nullable NSIndexPath *)indexPath;
/// 取消选择状态
- (void)qmui_clearsSelection;
/**
* row滚到指定的位置row的顶边缘和指定位置重叠row是最后一条等
* @param offsetY row要滚到的y值y值是相对于tableView的frame而言的
* @param indexPath indexPath indexPath
* @param animated
*/
- (void)qmui_scrollToRowFittingOffsetY:(CGFloat)offsetY atIndexPath:(nonnull NSIndexPath *)indexPath animated:(BOOL)animated;
/**
* tableHeaderView为UISearchBar时tableView为了实现searchbar滚到顶部自动吸附的效果self.contentSize.height至少为frame.size.height那么高self.contentSize获取tableView的内容大小是不准确的使`qmui_realContentSize`
*
* `qmui_realContentSize`section的framefooterView的frame比较得到实际的内容高度cellForRow调用使
*/
@property(nonatomic, assign, readonly) CGSize qmui_realContentSize;
/**
* UITableView的tableHeaderView如果是UISearchBar的话tableView.contentSize会强制设置为至少比bounds高headerView的吸附效果qmui_canScroll的判断不准确UITableView重写了qmui_canScroll方法
*/
- (BOOL)qmui_canScroll;
/**
UITableView iOS 11 iOS 11 使
@param updates insert/delete/reload/move calls
@param completion completion callback
*/
- (void)qmui_performBatchUpdates:(void (NS_NOESCAPE ^ _Nullable)(void))updates completion:(void (^ _Nullable)(BOOL finished))completion;
@end
NS_ASSUME_NONNULL_END