cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/UIKitExtensions/UITableView+QMUI.h

149 lines
9.2 KiB
C
Raw Permalink Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 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
#define PreferredValueForTableViewStyle(_style, _plain, _grouped, _insetGrouped) (_style == UITableViewStyleGrouped ? _grouped : (_style == UITableViewStyleInsetGrouped ? _insetGrouped : _plain))
/// 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注意 contentInset 所在的区域被视为“不可视”。
@property(nonatomic, readonly, nullable) NSArray<NSNumber *> *qmui_indexForVisibleSectionHeaders;
/// 获取正处于 pinned悬停在顶部状态的 sectionHeader 的序号,注意如果某个 section 的 numberOfRows 为 0则这个 section 天然无法被 pinned。
@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;
/// 获取当前 UITableView 用于呈现内容的区域的宽度,例如在全面屏下会减去 safeAreaInsets.left/right在 InsetGrouped 样式下会减去水平的缩进
@property(nonatomic, assign, readonly) CGFloat qmui_validContentWidth;
/**
* 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 DEPRECATED_MSG_ATTRIBUTE("请使用系统的 -[UITableView performBatchUpdates:completion:]QMUI 4.4.0 已不再支持 iOS 10没必要提供该兼容性之的接口了后续会删除。");
@end
/**
iOS 13 UITableViewStyleInsetGrouped cell Category iOS 12 iOS 13 Category cell
使
UITableView -[UITableView initWithStyle:UITableViewStyleInsetGrouped] tableView
UITableViewController -[UITableViewController initWithStyle:UITableViewStyleInsetGrouped] tableViewController
@c qmui_insetGroupedCornerRadius @c qmui_insetGroupedHorizontalInset indexPath -[UITableViewDelegate tableView:willDisplayCell:forRowAtIndexPath:] cell.layer.cornerRadius
@note sectionHeader/footer使 QMUITableViewHeaderFooterView UITableViewHeaderFooterView sizeThatFits:layoutSubviews sizeThatFits: size.width UITableViewHeaderFooterViewiOS 10 iOS 10
*/
@interface UITableView (QMUI_InsetGrouped)
/// 当使用 UITableViewStyleInsetGrouped 时可通过这个属性修改 cell 的圆角值,默认值为 10也即 iOS 13 系统默认表现。如果要为不同 indexPath 指定不同圆角值,可在 -[UITableViewDelegate tableView:willDisplayCell:forRowAtIndexPath:] 内修改 cell.layer.cornerRadius 的值。
@property(nonatomic, assign) CGFloat qmui_insetGroupedCornerRadius UI_APPEARANCE_SELECTOR;
/// 当使用 UITableViewStyleInsetGrouped 时可通过这个属性修改列表的左右缩进值,默认值为 20也即 iOS 13 系统默认表现。
@property(nonatomic, assign) CGFloat qmui_insetGroupedHorizontalInset UI_APPEARANCE_SELECTOR;
@end
NS_ASSUME_NONNULL_END