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

261 lines
12 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.
*/
//
// UIView+QMUI.h
// qmui
//
// Created by QMUI Team on 15/7/20.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "UIView+QMUIBorder.h"
NS_ASSUME_NONNULL_BEGIN
@interface UIView (QMUI)
/**
initWithFrame:CGRectMake(0, 0, size.width, size.height)
@param size size
@return
*/
- (instancetype)qmui_initWithSize:(CGSize)size;
/**
frame CGRectApplyAffineTransformWithAnchorPoint
*/
@property(nonatomic, assign) CGRect qmui_frameApplyTransform;
/**
iOS 11 self.safeAreaInsets UIEdgeInsetsZero
*/
@property(nonatomic, assign, readonly) UIEdgeInsets qmui_safeAreaInsets DEPRECATED_MSG_ATTRIBUTE("请使用系统的 UIView.safeAreaInsetsQMUI 4.4.0 已不再支持 iOS 10没必要提供该兼容性之的接口了后续会删除。");
/**
tintColor superview.tintColor
*/
@property(nonatomic, assign, readonly) BOOL qmui_tintColorCustomized;
/// 响应区域需要改变的大小,负值表示往外扩大,正值表示往内缩小。特别地,如果对 UISlider 使用,则扩大的是圆点的区域。
@property(nonatomic,assign) UIEdgeInsets qmui_outsideEdge;
/**
subviews
*/
- (void)qmui_removeAllSubviews;
/// 同 [UIView convertPoint:toView:],但支持在分属两个不同 window 的 view 之间进行坐标转换,也支持参数 view 直接传一个 window。
- (CGPoint)qmui_convertPoint:(CGPoint)point toView:(nullable UIView *)view;
/// 同 [UIView convertPoint:fromView:],但支持在分属两个不同 window 的 view 之间进行坐标转换,也支持参数 view 直接传一个 window。
- (CGPoint)qmui_convertPoint:(CGPoint)point fromView:(nullable UIView *)view;
/// 同 [UIView convertRect:toView:],但支持在分属两个不同 window 的 view 之间进行坐标转换,也支持参数 view 直接传一个 window。
- (CGRect)qmui_convertRect:(CGRect)rect toView:(nullable UIView *)view;
/// 同 [UIView convertRect:fromView:],但支持在分属两个不同 window 的 view 之间进行坐标转换,也支持参数 view 直接传一个 window。
- (CGRect)qmui_convertRect:(CGRect)rect fromView:(nullable UIView *)view;
+ (void)qmui_animateWithAnimated:(BOOL)animated duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;
+ (void)qmui_animateWithAnimated:(BOOL)animated duration:(NSTimeInterval)duration animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;
+ (void)qmui_animateWithAnimated:(BOOL)animated duration:(NSTimeInterval)duration animations:(void (^ __nullable)(void))animations;
+ (void)qmui_animateWithAnimated:(BOOL)animated duration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
@end
@interface UIView (QMUI_Block)
/**
UIView frame block setFrame:setBounds:setCenter:setTransform: rect frame [super setFrame:] 使 block setTransform: frame
@param view view 便使 weak
@param followingFrame setFrame: frame rect
@return 使 frame
@note followingFrame self.frame
*/
@property(nullable, nonatomic, copy) CGRect (^qmui_frameWillChangeBlock)(__kindof UIView *view, CGRect followingFrame);
/**
UIView frame block setFrame:setBounds:setCenter:setTransform:便 layoutSubviews 使 block
@param view view 便使 weak
@param precedingFrame frame
*/
@property(nullable, nonatomic, copy) void (^qmui_frameDidChangeBlock)(__kindof UIView *view, CGRect precedingFrame);
/**
- [UIView layoutSubviews] block
@param view view 便使 weak
*/
@property(nullable, nonatomic, copy) void (^qmui_layoutSubviewsBlock)(__kindof UIView *view);
/**
UIView sizeThatFits: block
@param view view 便使 weak
@param size sizeThatFits: size
@param superResult sizeThatFits:
*/
@property(nullable, nonatomic, copy) CGSize (^qmui_sizeThatFitsBlock)(__kindof UIView *view, CGSize size, CGSize superResult);
/**
tintColorDidChange block
@param view view 便使 weak
*/
@property(nullable, nonatomic, copy) void (^qmui_tintColorDidChangeBlock)(__kindof UIView *view);
/**
hitTest:withEvent: block
@param point point
@param event
@param super
*/
@property(nullable, nonatomic, copy) __kindof UIView * _Nullable (^qmui_hitTestBlock)(CGPoint point, UIEvent * _Nullable event, __kindof UIView * _Nullable originalView);
@end
@interface UIView (QMUI_ViewController)
/**
view view UIViewController [viewWillAppear, viewWillDisappear)
*/
@property(nonatomic, assign, readonly) BOOL qmui_visible;
/**
view UIViewController.view
*/
@property(nonatomic, assign) BOOL qmui_isControllerRootView;
/**
view UIViewController superview使
*/
@property(nullable, nonatomic, weak, readonly) __kindof UIViewController *qmui_viewController;
@end
@interface UIView (QMUI_Runtime)
/**
* UIView
* @param selector
* @return YES NO 使 UIView
*/
- (BOOL)qmui_hasOverrideUIKitMethod:(SEL)selector;
@end
/**
* 便 UIView UIImage UIView transform UIView
*/
@interface UIView (QMUI_Snapshotting)
- (UIImage *)qmui_snapshotLayerImage;
- (UIImage *)qmui_snapshotImageAfterScreenUpdates:(BOOL)afterScreenUpdates;
@end
/**
UIView setFrame: sizeThatFits view
@code
// 以前这么写
CGSize size = [view sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)];
view.frame = CGRectMake(x, y, width, size.height);
// 现在可以这么写:
view.frame = CGRectMake(x, y, width, QMUIViewSelfSizingHeight);
@endcode
*/
extern const CGFloat QMUIViewSelfSizingHeight;
/**
* view.frame 便 view view
*/
@interface UIView (QMUI_Layout)
/// 等价于 CGRectGetMinY(frame)
@property(nonatomic, assign) CGFloat qmui_top;
/// 等价于 CGRectGetMinX(frame)
@property(nonatomic, assign) CGFloat qmui_left;
/// 等价于 CGRectGetMaxY(frame)
@property(nonatomic, assign) CGFloat qmui_bottom;
/// 等价于 CGRectGetMaxX(frame)
@property(nonatomic, assign) CGFloat qmui_right;
/// 等价于 CGRectGetWidth(frame)
@property(nonatomic, assign) CGFloat qmui_width;
/// 等价于 CGRectGetHeight(frame)
@property(nonatomic, assign) CGFloat qmui_height;
/// 等价于 self.frame.size
@property(nonatomic, assign) CGSize qmui_size;
extern const CGSize QMUIViewFixedSizeNone;
/// 把当前 view 的大小设置为某个值并且固定下来(保证 setFrame:、setBounds: 等操作也无法影响它的 sizesizeThatFits: 返回的结果也以这个为准(但如果业务重写了就以业务的为准)
/// 默认为 QMUIViewFixedSizeNone也即不处理如果你设置过 fixedSize后续又希望去掉这个特性也可把 fixedSize 赋值为 QMUIViewFixedSizeNone 来清空)。
/// @example 例如 UIButton 的 imageView 是无法固定大小的,但如果你要把一张网络上下载的图(大小 不确定)作为 image 放到 button 里,就可以用 qmui_fixedSize 将 imageView 限制为某个尺寸,从而兼容不同的网络图片。
/// @warning 内部使用 qmui_sizeThatFitsBlock 实现(因为某些系统的 View 重写了 UIView 的 sizeThatFits为了保证 qmui_fixedSize 生效,只能用 qmui_sizeThatFitsBlock所以不要同时使用两者。
@property(nonatomic, assign) CGSize qmui_fixedSize;
/// 保持其他三个边缘的位置不变的情况下,将顶边缘拓展到某个指定的位置,注意高度会跟随变化。
@property(nonatomic, assign) CGFloat qmui_extendToTop;
/// 保持其他三个边缘的位置不变的情况下,将左边缘拓展到某个指定的位置,注意宽度会跟随变化。
@property(nonatomic, assign) CGFloat qmui_extendToLeft;
/// 保持其他三个边缘的位置不变的情况下,将底边缘拓展到某个指定的位置,注意高度会跟随变化。
@property(nonatomic, assign) CGFloat qmui_extendToBottom;
/// 保持其他三个边缘的位置不变的情况下,将右边缘拓展到某个指定的位置,注意宽度会跟随变化。
@property(nonatomic, assign) CGFloat qmui_extendToRight;
/// 获取当前 view 在 superview 内水平居中时的 left
@property(nonatomic, assign, readonly) CGFloat qmui_leftWhenCenterInSuperview;
/// 获取当前 view 在 superview 内垂直居中时的 top
@property(nonatomic, assign, readonly) CGFloat qmui_topWhenCenterInSuperview;
@end
@interface UIView (CGAffineTransform)
/// 获取当前 view 的 transform scale x
@property(nonatomic, assign, readonly) CGFloat qmui_scaleX;
/// 获取当前 view 的 transform scale y
@property(nonatomic, assign, readonly) CGFloat qmui_scaleY;
/// 获取当前 view 的 transform translation x
@property(nonatomic, assign, readonly) CGFloat qmui_translationX;
/// 获取当前 view 的 transform translation y
@property(nonatomic, assign, readonly) CGFloat qmui_translationY;
@end
/**
* Debug UIView view subviews view
*/
@interface UIView (QMUI_Debug)
/// 是否需要添加debug背景色默认NO
@property(nonatomic, assign) BOOL qmui_shouldShowDebugColor;
/// 是否每个view的背景色随机如果不随机则统一使用半透明红色默认NO
@property(nonatomic, assign) BOOL qmui_needsDifferentDebugColor;
@end
NS_ASSUME_NONNULL_END