UIView(FWAutoLayout)
@interface UIView (FWAutoLayout)
UIView自动布局分类,兼容UIView和UILayoutGuide(iOS9)
Note
如果约束条件完全相同,会自动更新约束而不是重新添加。 另外,默认布局方式使用LTR,如果需要RTL布局,可通过fwAutoLayoutRTL统一启用-
是否启用自动布局适配RTL,启用后自动将Left|Right转换为Leading|Trailing,默认NO
Note
如果项目兼容阿拉伯语等,需要启用RTL从右向左布局,开启此开关即可,无需修改布局代码 手工切换视图左右布局方法:[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;Declaration
Objective-C
@property (class, nonatomic) BOOL fw_autoLayoutRTL;
-
是否全局自动等比例缩放布局,默认NO
Note
启用后所有offset值都会自动*relativeScale,注意可能产生的影响。 启用后注意事项:- 屏幕宽度约束不能使用screenWidth约束,需要使用375设计标准
- 尽量不使用screenWidth固定屏幕宽度方式布局,推荐相对于父视图布局
- 只会对offset值生效,其他属性不受影响
- 如需特殊处理,可以指定某个视图关闭该功能
Declaration
Objective-C
@property (class, nonatomic) BOOL fw_autoScale;
-
视图是否自动等比例缩放布局,默认返回全局开关
Declaration
Objective-C
@property (nonatomic) BOOL fw_autoScale;
-
是否启用自动布局
Declaration
Objective-C
@property (nonatomic) BOOL fw_autoLayout;
-
执行子视图自动布局,自动计算子视图尺寸。需先将视图添加到界面(如设置为tableHeaderView),再调用即可(iOS8+)
Declaration
Objective-C
- (void)fw_autoLayoutSubviews;
-
计算动态布局视图指定宽度时的高度。使用AutoLayout必须约束完整,不使用AutoLayout会调用view的sizeThatFits:方法
Declaration
Objective-C
- (CGFloat)fw_layoutHeightWithWidth:(CGFloat)width;
-
计算动态布局视图指定高度时的宽度。使用AutoLayout必须约束完整,不使用AutoLayout会调用view的sizeThatFits:方法
Declaration
Objective-C
- (CGFloat)fw_layoutWidthWithHeight:(CGFloat)height;
-
设置水平方向抗压缩优先级
Declaration
Objective-C
@property (nonatomic) UILayoutPriority fw_compressionHorizontal;
-
设置垂直方向抗压缩优先级
Declaration
Objective-C
@property (nonatomic) UILayoutPriority fw_compressionVertical;
-
设置水平方向抗拉伸优先级
Declaration
Objective-C
@property (nonatomic) UILayoutPriority fw_huggingHorizontal;
-
设置垂直方向抗拉伸优先级
Declaration
Objective-C
@property (nonatomic) UILayoutPriority fw_huggingVertical;
-
设置视图是否收缩,默认NO,YES时常量值为0,NO时常量值为原始值
Declaration
Objective-C
@property (nonatomic) BOOL fw_collapsed;
-
设置视图是否自动收缩,如image为nil,text为nil、@“"时自动收缩,默认NO
Declaration
Objective-C
@property (nonatomic) BOOL fw_autoCollapse;
-
设置视图是否隐藏时自动收缩、显示时自动展开,默认NO
Declaration
Objective-C
@property (nonatomic) BOOL fw_hiddenCollapse;
-
添加视图的收缩常量,必须先添加才能生效
Declaration
Objective-C
- (void)fw_addCollapseConstraint:(nonnull NSLayoutConstraint *)constraint;
-
父视图居中
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_alignCenterToSuperview;
Return Value
约束数组
-
父视图居中偏移指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_alignCenterToSuperviewWithOffset: (CGPoint)offset;
Parameters
offset
偏移距离
Return Value
约束数组
-
父视图属性居中
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxisToSuperview:(NSLayoutAttribute)axis;
Parameters
axis
居中属性
Return Value
布局约束
-
父视图属性居中偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxisToSuperview:(NSLayoutAttribute)axis withOffset:(CGFloat)offset;
Parameters
axis
居中属性
offset
偏移距离
Return Value
布局约束
-
与另一视图居中相同
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxis:(NSLayoutAttribute)axis toView:(nonnull id)otherView;
Parameters
axis
居中属性
otherView
另一视图或UILayoutGuide,下同
Return Value
布局约束
-
与另一视图居中偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxis:(NSLayoutAttribute)axis toView:(nonnull id)otherView withOffset:(CGFloat)offset;
Parameters
axis
居中属性
otherView
另一视图
offset
偏移距离
Return Value
布局约束
-
与另一视图居中指定比例
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxis:(NSLayoutAttribute)axis toView:(nonnull id)otherView withMultiplier:(CGFloat)multiplier;
Parameters
axis
居中属性
otherView
另一视图
multiplier
指定比例
Return Value
布局约束
-
与父视图四条边属性相同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinEdgesToSuperview;
Return Value
约束数组
-
与父视图四条边属性距离指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinEdgesToSuperviewWithInsets: (UIEdgeInsets)insets;
Parameters
insets
指定距离insets
Return Value
约束数组
-
与父视图三条边属性距离指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *) fw_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)insets excludingEdge:(NSLayoutAttribute)edge;
Parameters
insets
指定距离insets
edge
排除的边
Return Value
约束数组
-
与父视图水平方向两条边属性相同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinHorizontalToSuperview;
Return Value
约束数组
-
与父视图水平方向两条边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinHorizontalToSuperviewWithInset: (CGFloat)inset;
Parameters
inset
偏移距离
Return Value
约束数组
-
与父视图垂直方向两条边属性相同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinVerticalToSuperview;
Return Value
约束数组
-
与父视图垂直方向两条边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinVerticalToSuperviewWithInset: (CGFloat)inset;
Parameters
inset
偏移距离
Return Value
约束数组
-
与父视图边属性相同
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdgeToSuperview:(NSLayoutAttribute)edge;
Parameters
edge
指定边属性
Return Value
布局约束
-
与父视图边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdgeToSuperview:(NSLayoutAttribute)edge withInset:(CGFloat)inset;
Parameters
edge
指定边属性
inset
偏移距离
Return Value
布局约束
-
与父视图边属性偏移指定距离,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdgeToSuperview:(NSLayoutAttribute)edge withInset:(CGFloat)inset relation: (NSLayoutRelation)relation;
Parameters
edge
指定边属性
inset
偏移距离
relation
约束关系
Return Value
布局约束
-
与指定视图边属性相同
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdge:(NSLayoutAttribute)edge toEdge:(NSLayoutAttribute)toEdge ofView:(nonnull id)otherView;
Parameters
edge
指定边属性
toEdge
另一视图边属性
otherView
另一视图
Return Value
布局约束
-
与指定视图边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdge:(NSLayoutAttribute)edge toEdge:(NSLayoutAttribute)toEdge ofView:(nonnull id)otherView withOffset:(CGFloat)offset;
Parameters
edge
指定边属性
toEdge
另一视图边属性
otherView
另一视图
offset
偏移距离
Return Value
布局约束
-
与指定视图边属性偏移指定距离,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdge:(NSLayoutAttribute)edge toEdge:(NSLayoutAttribute)toEdge ofView:(nonnull id)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
Parameters
edge
指定边属性
toEdge
另一视图边属性
otherView
另一视图
offset
偏移距离
relation
约束关系
Return Value
布局约束
-
父视图安全区域居中。iOS11以下使用Superview实现,下同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_alignCenterToSafeArea;
Return Value
约束数组
-
父视图安全区域居中偏移指定距离。iOS11以下使用Superview实现,下同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_alignCenterToSafeAreaWithOffset: (CGPoint)offset;
Parameters
offset
偏移距离
Return Value
约束数组
-
父视图安全区域属性居中
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxisToSafeArea:(NSLayoutAttribute)axis;
Parameters
axis
居中属性
Return Value
布局约束
-
父视图安全区域属性居中偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_alignAxisToSafeArea:(NSLayoutAttribute)axis withOffset:(CGFloat)offset;
Parameters
axis
居中属性
offset
偏移距离
Return Value
布局约束
-
与父视图安全区域四条边属性相同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinEdgesToSafeArea;
Return Value
约束数组
-
与父视图安全区域四条边属性距离指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinEdgesToSafeAreaWithInsets: (UIEdgeInsets)insets;
Parameters
insets
指定距离insets
Return Value
约束数组
-
与父视图安全区域三条边属性距离指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *) fw_pinEdgesToSafeAreaWithInsets:(UIEdgeInsets)insets excludingEdge:(NSLayoutAttribute)edge;
Parameters
insets
指定距离insets
edge
排除的边
Return Value
约束数组
-
与父视图安全区域水平方向两条边属性相同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinHorizontalToSafeArea;
Return Value
约束数组
-
与父视图安全区域水平方向两条边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinHorizontalToSafeAreaWithInset: (CGFloat)inset;
Parameters
inset
偏移距离
Return Value
约束数组
-
与父视图安全区域垂直方向两条边属性相同
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinVerticalToSafeArea;
Return Value
约束数组
-
与父视图安全区域垂直方向两条边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_pinVerticalToSafeAreaWithInset: (CGFloat)inset;
Parameters
inset
偏移距离
Return Value
约束数组
-
与父视图安全区域边属性相同
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdgeToSafeArea:(NSLayoutAttribute)edge;
Parameters
edge
指定边属性
Return Value
布局约束
-
与父视图安全区域边属性偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdgeToSafeArea:(NSLayoutAttribute)edge withInset:(CGFloat)inset;
Parameters
edge
指定边属性
inset
偏移距离
Return Value
布局约束
-
与父视图安全区域边属性偏移指定距离,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_pinEdgeToSafeArea:(NSLayoutAttribute)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
Parameters
edge
指定边属性
inset
偏移距离
relation
约束关系
Return Value
布局约束
-
设置宽高尺寸
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_setDimensionsToSize:(CGSize)size;
Parameters
size
尺寸大小
Return Value
约束数组
-
设置某个尺寸
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_setDimension:(NSLayoutAttribute)dimension toSize:(CGFloat)size;
Parameters
dimension
尺寸属性
size
尺寸大小
Return Value
布局约束
-
设置某个尺寸,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_setDimension:(NSLayoutAttribute)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation;
Parameters
dimension
尺寸属性
size
尺寸大小
relation
约束关系
Return Value
布局约束
-
与视图自身尺寸属性指定比例
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension withMultiplier:(CGFloat)multiplier;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
multiplier
指定比例
Return Value
布局约束
-
与视图自身尺寸属性指定比例,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
multiplier
指定比例
relation
约束关系
Return Value
布局约束
-
与指定视图尺寸属性相同
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension ofView:(nonnull id)otherView;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
otherView
目标视图
Return Value
布局约束
-
与指定视图尺寸属性相差指定大小
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension ofView:(nonnull id)otherView withOffset:(CGFloat)offset;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
otherView
目标视图
offset
相差大小
Return Value
布局约束
-
与指定视图尺寸属性相差指定大小,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension ofView:(nonnull id)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
otherView
目标视图
offset
相差大小
relation
约束关系
Return Value
布局约束
-
与指定视图尺寸属性指定比例
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension ofView:(nonnull id)otherView withMultiplier:(CGFloat)multiplier;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
otherView
目标视图
multiplier
指定比例
Return Value
布局约束
-
与指定视图尺寸属性指定比例,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *)fw_matchDimension:(NSLayoutAttribute)dimension toDimension:(NSLayoutAttribute)toDimension ofView:(nonnull id)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
Parameters
dimension
尺寸属性
toDimension
目标尺寸属性
otherView
目标视图
multiplier
指定比例
relation
约束关系
Return Value
布局约束
-
与指定视图属性相同
Declaration
Objective-C
- (nonnull NSLayoutConstraint *) fw_constrainAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
Return Value
布局约束
-
与指定视图属性偏移指定距离
Declaration
Objective-C
- (nonnull NSLayoutConstraint *) fw_constrainAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView withOffset:(CGFloat)offset;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
offset
偏移距离
Return Value
布局约束
-
与指定视图属性偏移指定距离,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *) fw_constrainAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
offset
偏移距离
relation
约束关系
Return Value
布局约束
-
与指定视图属性指定比例
Declaration
Objective-C
- (nonnull NSLayoutConstraint *) fw_constrainAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView withMultiplier:(CGFloat)multiplier;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
multiplier
指定比例
Return Value
布局约束
-
与指定视图属性指定比例,指定关系
Declaration
Objective-C
- (nonnull NSLayoutConstraint *) fw_constrainAttribute:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
multiplier
指定比例
relation
约束关系
Return Value
布局约束
-
修改最近一批添加或更新的布局约束偏移值
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_setOffset:(CGFloat)offset;
-
修改最近一批添加或更新的布局约束内间距值
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_setInset:(CGFloat)inset;
-
修改最近一批添加或更新的布局约束优先级
Declaration
Objective-C
- (nonnull NSArray<NSLayoutConstraint *> *)fw_setPriority: (UILayoutPriority)priority;
-
获取添加的与父视图属性的约束
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraintToSuperview: (NSLayoutAttribute)attribute;
Parameters
attribute
指定属性
Return Value
布局约束
-
获取添加的与父视图属性的约束,指定关系
Declaration
Objective-C
- (nullable NSLayoutConstraint *) fw_constraintToSuperview:(NSLayoutAttribute)attribute relation:(NSLayoutRelation)relation;
Parameters
attribute
指定属性
relation
约束关系
Return Value
布局约束
-
获取添加的与父视图安全区域属性的约束
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraintToSafeArea: (NSLayoutAttribute)attribute;
Parameters
attribute
指定属性
Return Value
布局约束
-
获取添加的与父视图安全区域属性的约束,指定关系
Declaration
Objective-C
- (nullable NSLayoutConstraint *) fw_constraintToSafeArea:(NSLayoutAttribute)attribute relation:(NSLayoutRelation)relation;
Parameters
attribute
指定属性
relation
约束关系
Return Value
布局约束
-
获取添加的与指定视图属性的约束
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraint:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
Return Value
布局约束
-
获取添加的与指定视图属性的约束,指定关系
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraint:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView relation:(NSLayoutRelation)relation;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
relation
约束关系
Return Value
布局约束
-
获取添加的与指定视图属性指定比例的约束
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraint:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView withMultiplier:(CGFloat)multiplier;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
multiplier
指定比例
Return Value
布局约束
-
获取添加的与指定视图属性指定比例的约束,指定关系
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraint:(NSLayoutAttribute)attribute toAttribute:(NSLayoutAttribute)toAttribute ofView:(nullable id)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation;
Parameters
attribute
指定属性
toAttribute
目标视图属性
otherView
目标视图
multiplier
指定比例
relation
约束关系
Return Value
布局约束
-
设置约束保存键名,方便更新约束常量
Declaration
Objective-C
- (void)fw_setConstraint:(nullable NSLayoutConstraint *)constraint forKey:(nonnull id<NSCopying>)key;
Parameters
constraint
布局约束
key
保存key
-
获取键名对应约束
Declaration
Objective-C
- (nullable NSLayoutConstraint *)fw_constraintForKey:(nonnull id<NSCopying>)key;
Parameters
key
保存key
Return Value
布局约束
-
最近一批添加或更新的布局约束
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSArray<NSLayoutConstraint *> *fw_lastConstraints;
-
最近一条添加或更新的布局约束
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSLayoutConstraint *fw_lastConstraint;
-
获取当前所有约束,不包含Key
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSArray<NSLayoutConstraint *> *fw_allConstraints;
Return Value
约束列表
-
移除当前指定约束,不包含Key
Declaration
Objective-C
- (void)fw_removeConstraint:(nonnull NSLayoutConstraint *)constraint;
-
移除当前所有约束,不包含Key
Declaration
Objective-C
- (void)fw_removeAllConstraints;
-
链式布局对象
Declaration
Objective-C
@property (nonatomic, strong, readonly) NS_SWIFT_UNAVAILABLE("") FWLayoutChain *fw_layoutChain;
-
链式布局句柄
Declaration
Objective-C
- (void)fw_layoutMaker: (nonnull void (^)(FWLayoutChain *_Nonnull __strong))block;
-
添加点击手势事件,默认子视图也会响应此事件。如要屏蔽之,解决方法:1、子视图设为UIButton;2、子视图添加空手势事件
Declaration
Objective-C
- (void)fw_addTapGestureWithTarget:(nonnull id)target action:(nonnull SEL)action;
-
添加点击手势句柄,同上
Declaration
Objective-C
- (nonnull NSString *)fw_addTapGestureWithBlock: (nonnull void (^)(id _Nonnull __strong))block;
-
根据唯一标志移除点击手势句柄
Declaration
Objective-C
- (void)fw_removeTapGesture:(nullable NSString *)identifier;
-
移除所有点击手势
Declaration
Objective-C
- (void)fw_removeAllTapGestures;
-
顶部纵坐标,frame.origin.y
Declaration
Objective-C
@property (nonatomic) CGFloat fw_top;
-
底部纵坐标,frame.origin.y + frame.size.height
Declaration
Objective-C
@property (nonatomic) CGFloat fw_bottom;
-
左边横坐标,frame.origin.x
Declaration
Objective-C
@property (nonatomic) CGFloat fw_left;
-
右边横坐标,frame.origin.x + frame.size.width
Declaration
Objective-C
@property (nonatomic) CGFloat fw_right;
-
宽度,frame.size.width
Declaration
Objective-C
@property (nonatomic) CGFloat fw_width;
-
高度,frame.size.height
Declaration
Objective-C
@property (nonatomic) CGFloat fw_height;
-
中心横坐标,center.x
Declaration
Objective-C
@property (nonatomic) CGFloat fw_centerX;
-
中心纵坐标,center.y
Declaration
Objective-C
@property (nonatomic) CGFloat fw_centerY;
-
起始横坐标,frame.origin.x
Declaration
Objective-C
@property (nonatomic) CGFloat fw_x;
-
起始纵坐标,frame.origin.y
Declaration
Objective-C
@property (nonatomic) CGFloat fw_y;
-
起始坐标,frame.origin
Declaration
Objective-C
@property (nonatomic) CGPoint fw_origin;
-
大小,frame.size
Declaration
Objective-C
@property (nonatomic) CGSize fw_size;
-
视图是否可见,视图hidden为NO、alpha>0.01、window存在且size不为0才认为可见
Declaration
Objective-C
@property (nonatomic, readonly) BOOL fw_isViewVisible;
-
获取响应的视图控制器
Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) __kindof UIViewController *fw_viewController;
-
设置额外热区(点击区域)
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets fw_touchInsets;
-
设置自动计算适合高度的frame,需实现sizeThatFits:方法
Declaration
Objective-C
@property (nonatomic) CGRect fw_fitFrame;
-
计算当前视图适合大小,需实现sizeThatFits:方法
Declaration
Objective-C
@property (nonatomic, readonly) CGSize fw_fitSize;
-
计算指定边界,当前视图适合大小,需实现sizeThatFits:方法
Declaration
Objective-C
- (CGSize)fw_fitSizeWithDrawSize:(CGSize)drawSize;
-
根据tag查找subview,仅从subviews中查找
Declaration
Objective-C
- (nullable __kindof UIView *)fw_subviewWithTag:(NSInteger)tag;
-
设置阴影颜色、偏移和半径
Declaration
Objective-C
- (void)fw_setShadowColor:(nullable UIColor *)color offset:(CGSize)offset radius:(CGFloat)radius;
-
绘制四边边框
Declaration
Objective-C
- (void)fw_setBorderColor:(nullable UIColor *)color width:(CGFloat)width;
-
绘制四边边框和四角圆角
Declaration
Objective-C
- (void)fw_setBorderColor:(nullable UIColor *)color width:(CGFloat)width cornerRadius:(CGFloat)radius;
-
绘制四角圆角
Declaration
Objective-C
- (void)fw_setCornerRadius:(CGFloat)radius;
-
绘制单边或多边边框Layer。frame必须存在(添加视图后可调用layoutIfNeeded更新frame)
Declaration
Objective-C
- (void)fw_setBorderLayer:(UIRectEdge)edge color:(nullable UIColor *)color width:(CGFloat)width;
-
绘制单边或多边边框Layer。frame必须存在(添加视图后可调用layoutIfNeeded更新frame)
Declaration
Objective-C
- (void)fw_setBorderLayer:(UIRectEdge)edge color:(nullable UIColor *)color width:(CGFloat)width leftInset:(CGFloat)leftInset rightInset:(CGFloat)rightInset;
-
绘制单个或多个边框圆角,frame必须存在(添加视图后可调用layoutIfNeeded更新frame)
Declaration
Objective-C
- (void)fw_setCornerLayer:(UIRectCorner)corner radius:(CGFloat)radius;
-
绘制单个或多个边框圆角和四边边框,frame必须存在(添加视图后可调用layoutIfNeeded更新frame)
Declaration
Objective-C
- (void)fw_setCornerLayer:(UIRectCorner)corner radius:(CGFloat)radius borderColor:(nullable UIColor *)color width:(CGFloat)width;
-
绘制单边或多边边框视图。使用AutoLayout
Declaration
Objective-C
- (void)fw_setBorderView:(UIRectEdge)edge color:(nullable UIColor *)color width:(CGFloat)width;
-
绘制单边或多边边框。使用AutoLayout
Declaration
Objective-C
- (void)fw_setBorderView:(UIRectEdge)edge color:(nullable UIColor *)color width:(CGFloat)width leftInset:(CGFloat)leftInset rightInset:(CGFloat)rightInset;
-
开始倒计时,从window移除时自动取消,回调参数为剩余时间
Declaration
Objective-C
- (nonnull dispatch_source_t)fw_startCountDown:(NSInteger)seconds block: (nonnull void (^)(NSInteger))block;
-
显示警告框(精简版),默认关闭按钮
Declaration
Objective-C
- (void)fw_showAlertWithTitle:(nullable id)title message:(nullable id)message;
Parameters
title
警告框标题
message
警告框消息
-
显示警告框(简单版)
Declaration
Objective-C
- (void)fw_showAlertWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
警告框标题
message
警告框消息
cancel
取消按钮标题,默认关闭
cancelBlock
取消按钮事件
-
显示警告框(详细版)
Declaration
Objective-C
- (void)fw_showAlertWithTitle:(nullable id)title message:(nullable id)message style:(FWAlertStyle)style cancel:(nullable id)cancel actions:(nullable NSArray *)actions actionBlock:(nullable void (^)(NSInteger))actionBlock cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
警告框标题
message
警告框消息
style
警告框样式
cancel
取消按钮标题,默认单按钮关闭,多按钮取消
actions
动作按钮标题列表
actionBlock
动作按钮点击事件,参数为索引index
cancelBlock
取消按钮事件
-
显示确认框(简单版)
Declaration
Objective-C
- (void)fw_showConfirmWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel confirm:(nullable id)confirm confirmBlock:(nullable void (^)(void))confirmBlock;
Parameters
title
确认框标题
message
确认框消息
cancel
取消按钮文字,默认取消
confirm
确认按钮文字,默认确定
confirmBlock
确认按钮事件
-
显示确认框(详细版)
Declaration
Objective-C
- (void)fw_showConfirmWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel confirm:(nullable id)confirm confirmBlock:(nullable void (^)(void))confirmBlock cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
确认框标题
message
确认框消息
cancel
取消按钮文字,默认取消
confirm
确认按钮文字,默认确定
confirmBlock
确认按钮事件
cancelBlock
取消按钮事件
-
显示输入框(简单版)
Declaration
Objective-C
- (void)fw_showPromptWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel confirm:(nullable id)confirm confirmBlock:(nullable void (^)(NSString *_Nonnull __strong)) confirmBlock;
Parameters
title
输入框标题
message
输入框消息
cancel
取消按钮文字,默认取消
confirm
确认按钮文字,默认确定
confirmBlock
确认按钮事件,参数为输入值
-
显示输入框(详细版)
Declaration
Objective-C
- (void)fw_showPromptWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel confirm:(nullable id)confirm promptBlock:(nullable void (^)( UITextField *_Nonnull __strong))promptBlock confirmBlock:(nullable void (^)(NSString *_Nonnull __strong)) confirmBlock cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
输入框标题
message
输入框消息
cancel
取消按钮文字,默认取消
confirm
确认按钮文字,默认确定
promptBlock
输入框初始化事件,参数为输入框
confirmBlock
确认按钮事件,参数为输入值
cancelBlock
取消按钮事件
-
显示输入框(复杂版)
Declaration
Objective-C
- (void) fw_showPromptWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel confirm:(nullable id)confirm promptCount:(NSInteger)promptCount promptBlock:(nullable void (^)(UITextField *_Nonnull __strong, NSInteger))promptBlock confirmBlock: (nullable void (^)(NSArray<NSString *> *_Nonnull __strong)) confirmBlock cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
输入框标题
message
输入框消息
cancel
取消按钮文字,默认取消
confirm
确认按钮文字,默认确定
promptCount
输入框数量
promptBlock
输入框初始化事件,参数为输入框和索引index
confirmBlock
确认按钮事件,参数为输入值数组
cancelBlock
取消按钮事件
-
-fw_showAlertWithTitle:
message: style: cancel: actions: promptCount: promptBlock: actionBlock: cancelBlock: customBlock: 显示弹出框(完整版)
Declaration
Objective-C
- (void)fw_showAlertWithTitle:(nullable id)title message:(nullable id)message style:(FWAlertStyle)style cancel:(nullable id)cancel actions:(nullable NSArray *)actions promptCount:(NSInteger)promptCount promptBlock:(nullable void (^)(UITextField *_Nonnull __strong, NSInteger))promptBlock actionBlock: (nullable void (^)(NSArray<NSString *> *_Nonnull __strong, NSInteger))actionBlock cancelBlock:(nullable void (^)(void))cancelBlock customBlock: (nullable void (^)(id _Nonnull __strong))customBlock;
Parameters
title
操作表标题
message
操作表消息
style
警告框样式
cancel
取消按钮标题,默认Alert单按钮关闭,Alert多按钮取消
actions
动作按钮标题列表
promptCount
输入框数量
promptBlock
输入框初始化事件,参数为输入框和索引index
actionBlock
动作按钮点击事件,参数为输入值数组和索引index
cancelBlock
取消按钮事件
customBlock
自定义弹出框事件
-
显示操作表(无动作)
Declaration
Objective-C
- (void)fw_showSheetWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
操作表标题
message
操作表消息
cancel
取消按钮标题,默认取消
cancelBlock
取消按钮事件
-
显示操作表(简单版)
Declaration
Objective-C
- (void)fw_showSheetWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel actions:(nullable NSArray *)actions actionBlock:(nullable void (^)(NSInteger))actionBlock;
Parameters
title
操作表标题
message
操作表消息
cancel
取消按钮标题,默认取消
actions
动作按钮标题列表
actionBlock
动作按钮点击事件,参数为索引index
-
显示操作表(详细版)
Declaration
Objective-C
- (void)fw_showSheetWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel actions:(nullable NSArray *)actions currentIndex:(NSInteger)currentIndex actionBlock:(nullable void (^)(NSInteger))actionBlock cancelBlock:(nullable void (^)(void))cancelBlock;
Parameters
title
操作表标题
message
操作表消息
cancel
取消按钮标题,默认取消
actions
动作按钮标题列表
currentIndex
当前选中动作索引
actionBlock
动作按钮点击事件,参数为索引index
cancelBlock
取消按钮事件
-
显示操作表(完整版)
Declaration
Objective-C
- (void)fw_showSheetWithTitle:(nullable id)title message:(nullable id)message cancel:(nullable id)cancel actions:(nullable NSArray *)actions currentIndex:(NSInteger)currentIndex actionBlock:(nullable void (^)(NSInteger))actionBlock cancelBlock:(nullable void (^)(void))cancelBlock customBlock: (nullable void (^)(id _Nonnull __strong))customBlock;
Parameters
title
操作表标题
message
操作表消息
cancel
取消按钮标题,默认Alert单按钮关闭,Alert多按钮或Sheet取消
actions
动作按钮标题列表
currentIndex
当前选中动作索引
actionBlock
动作按钮点击事件,参数为输入值数组和索引index
cancelBlock
取消按钮事件
customBlock
自定义弹出框事件
-
手工隐藏弹出框,完成后回调
Declaration
Objective-C
- (void)fw_hideAlert:(BOOL)animated completion:(nullable void (^)(void))completion;
Parameters
animated
是否执行动画
completion
完成回调
-
判断是否正在显示弹出框
Declaration
Objective-C
@property (nonatomic, readonly) BOOL fw_isShowingAlert;
-
显示右上角提醒灯,上右偏移指定距离
Declaration
Objective-C
- (void)fw_showBadgeView:(nonnull FWBadgeView *)badgeView badgeValue:(nullable NSString *)badgeValue;
-
隐藏提醒灯
Declaration
Objective-C
- (void)fw_hideBadgeView;
-
Undocumented
Declaration
Objective-C
@property (nullable, nonatomic, strong) FWDrawerView *fw_drawerView
-
设置抽屉拖拽效果。如果view为滚动视图,自动处理与滚动视图pan手势冲突的问题
Declaration
Objective-C
- (nonnull FWDrawerView *) fw_drawerView:(UISwipeGestureRecognizerDirection)direction positions:(nonnull NSArray<NSNumber *> *)positions kickbackHeight:(CGFloat)kickbackHeight callback:(nullable void (^)(CGFloat, BOOL))callback;
Parameters
direction
拖拽方向,如向上拖动视图时为Up,默认向上
positions
抽屉位置,至少两级,相对于view父视图的originY位置
kickbackHeight
回弹高度,拖拽小于该高度执行回弹
callback
抽屉视图位移回调,参数为相对父视图的origin位置和是否拖拽完成的标记
Return Value
抽屉拖拽视图
-
自定义空界面插件,未设置时自动从插件池加载
Declaration
Objective-C
@property (nonatomic, strong, nullable) id<FWEmptyPlugin> fw_emptyPlugin;
-
设置空界面外间距,默认zero
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets fw_emptyInsets;
-
是否显示空界面
Declaration
Objective-C
@property (nonatomic, readonly) BOOL fw_hasEmptyView;
-
显示空界面
Declaration
Objective-C
- (void)fw_showEmptyView;
-
显示空界面加载视图
Declaration
Objective-C
- (void)fw_showEmptyViewLoading;
-
显示空界面,指定文本
Declaration
Objective-C
- (void)fw_showEmptyViewWithText:(nullable NSString *)text;
-
显示空界面,指定文本和详细文本
Declaration
Objective-C
- (void)fw_showEmptyViewWithText:(nullable NSString *)text detail:(nullable NSString *)detail;
-
显示空界面,指定文本、详细文本和图片
Declaration
Objective-C
- (void)fw_showEmptyViewWithText:(nullable NSString *)text detail:(nullable NSString *)detail image:(nullable UIImage *)image;
-
显示空界面,指定文本、详细文本、图片和动作按钮
Declaration
Objective-C
- (void)fw_showEmptyViewWithText:(nullable NSString *)text detail:(nullable NSString *)detail image:(nullable UIImage *)image action:(nullable NSString *)action block:(nullable void (^)(id _Nonnull __strong))block;
-
显示空界面,指定文本、详细文本、图片、是否显示加载视图和动作按钮
Declaration
Objective-C
- (void)fw_showEmptyViewWithText:(nullable NSString *)text detail:(nullable NSString *)detail image:(nullable UIImage *)image loading:(BOOL)loading action:(nullable NSString *)action block:(nullable void (^)(id _Nonnull __strong))block;
-
显示空界面,指定文本、详细文本、图片、是否显示加载视图和最多两个动作按钮
Declaration
Objective-C
- (void)fw_showEmptyViewWithText:(nullable NSString *)text detail:(nullable NSString *)detail image:(nullable UIImage *)image loading:(BOOL)loading actions:(nullable NSArray<NSString *> *)actions block:(nullable void (^)(NSInteger, id _Nonnull __strong))block;
-
隐藏空界面
Declaration
Objective-C
- (void)fw_hideEmptyView;
-
从Camera选取单张图片(简单版)
Declaration
Objective-C
- (void)fw_showImageCameraWithAllowsEditing:(BOOL)allowsEditing completion:(nonnull void (^)( UIImage *_Nullable __strong, BOOL))completion;
Parameters
allowsEditing
是否允许编辑
completion
完成回调,主线程。参数1为图片,2为是否取消
-
从Camera选取单张图片(详细版)
Declaration
Objective-C
- (void)fw_showImageCameraWithFilterType:(FWImagePickerFilterType)filterType allowsEditing:(BOOL)allowsEditing customBlock:(nullable void (^)( id _Nonnull __strong))customBlock completion: (nonnull void (^)(id _Nullable __strong, id _Nullable __strong, BOOL))completion;
Parameters
filterType
过滤类型,默认0同系统
allowsEditing
是否允许编辑
customBlock
自定义配置句柄,默认nil
completion
完成回调,主线程。参数1为对象(UIImage|PHLivePhoto|NSURL),2为结果信息,3为是否取消
-
从图片库选取单张图片(简单版)
Declaration
Objective-C
- (void)fw_showImagePickerWithAllowsEditing:(BOOL)allowsEditing completion:(nonnull void (^)( UIImage *_Nullable __strong, BOOL))completion;
Parameters
allowsEditing
是否允许编辑
completion
完成回调,主线程。参数1为图片,2为是否取消
-
从图片库选取多张图片(简单版)
Declaration
Objective-C
- (void)fw_showImagePickerWithSelectionLimit:(NSInteger)selectionLimit allowsEditing:(BOOL)allowsEditing completion: (nonnull void (^)( NSArray<UIImage *> *_Nonnull __strong, NSArray *_Nonnull __strong, BOOL))completion;
Parameters
selectionLimit
最大选择数量
allowsEditing
是否允许编辑
completion
完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消
-
从图片库选取多张图片(详细版)
Declaration
Objective-C
- (void)fw_showImagePickerWithFilterType:(FWImagePickerFilterType)filterType selectionLimit:(NSInteger)selectionLimit allowsEditing:(BOOL)allowsEditing customBlock:(nullable void (^)( id _Nonnull __strong))customBlock completion: (nonnull void (^)(NSArray *_Nonnull __strong, NSArray *_Nonnull __strong, BOOL))completion;
Parameters
filterType
过滤类型,默认0同系统
selectionLimit
最大选择数量
allowsEditing
是否允许编辑
customBlock
自定义配置句柄,默认nil
completion
完成回调,主线程。参数1为对象数组(UIImage|PHLivePhoto|NSURL),2位结果数组,3为是否取消
-
显示图片预览(简单版)
Declaration
Objective-C
- (void)fw_showImagePreviewWithImageURLs:(nonnull NSArray *)imageURLs imageInfos:(nullable NSArray *)imageInfos currentIndex:(NSInteger)currentIndex sourceView:(nullable id _Nullable (^)(NSInteger)) sourceView;
Parameters
imageURLs
预览图片列表,支持NSString|UIImage|PHLivePhoto|AVPlayerItem类型
imageInfos
自定义图片信息数组
currentIndex
当前索引,默认0
sourceView
来源视图,可选,支持UIView|NSValue.CGRect,默认nil
-
-fw_showImagePreviewWithImageURLs:
imageInfos: currentIndex: sourceView: placeholderImage: renderBlock: customBlock: 显示图片预览(详细版)
Declaration
Objective-C
- (void)fw_showImagePreviewWithImageURLs:(nonnull NSArray *)imageURLs imageInfos:(nullable NSArray *)imageInfos currentIndex:(NSInteger)currentIndex sourceView:(nullable id _Nullable (^)(NSInteger)) sourceView placeholderImage:(nullable UIImage *_Nullable (^)( NSInteger))placeholderImage renderBlock:(nullable void (^)( __kindof UIView *_Nonnull __strong, NSInteger))renderBlock customBlock:(nullable void (^)( id _Nonnull __strong))customBlock;
Parameters
imageURLs
预览图片列表,支持NSString|UIImage|PHLivePhoto|AVPlayerItem类型
imageInfos
自定义图片信息数组
currentIndex
当前索引,默认0
sourceView
来源视图句柄,支持UIView|NSValue.CGRect,默认nil
placeholderImage
占位图或缩略图句柄,默认nil
renderBlock
自定义渲染句柄,默认nil
customBlock
自定义句柄,默认nil
-
绑定统计点击事件,触发管理器。view为添加的Tap手势(需先添加手势),control为TouchUpInside|ValueChanged,tableView|collectionView为Select(需先设置delegate)
Declaration
Objective-C
@property (nonatomic, strong, nullable) FWStatisticalObject *fw_statisticalClick;
-
绑定统计点击事件,仅触发回调。view为添加的Tap手势(需先添加手势),control为TouchUpInside|ValueChanged,tableView|collectionView为Select(需先设置delegate)
Declaration
Objective-C
@property (nonatomic, copy, nullable) FWStatisticalBlock fw_statisticalClickBlock;
-
手工触发统计点击事件,更新点击次数,列表可指定cell和位置,可重复触发
Declaration
Objective-C
- (void)fw_statisticalTriggerClick:(nullable UIView *)cell indexPath:(nullable NSIndexPath *)indexPath;
-
绑定统计曝光事件,触发管理器。如果对象发生变化(indexPath|name|object),也会触发
Declaration
Objective-C
@property (nonatomic, strong, nullable) FWStatisticalObject *fw_statisticalExposure;
-
绑定统计曝光事件,仅触发回调
Declaration
Objective-C
@property (nonatomic, copy, nullable) FWStatisticalBlock fw_statisticalExposureBlock;
-
手工触发统计曝光事件,更新曝光次数和时长,列表可指定cell和位置,duration为单次曝光时长(0表示开始),可重复触发
Declaration
Objective-C
- (void)fw_statisticalTriggerExposure:(nullable UIView *)cell indexPath:(nullable NSIndexPath *)indexPath duration:(NSTimeInterval)duration;
-
自定义吐司插件,未设置时自动从插件池加载
Declaration
Objective-C
@property (nonatomic, strong, nullable) id<FWToastPlugin> fw_toastPlugin;
-
设置吐司外间距,默认zero
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets fw_toastInsets;
-
显示加载吐司,需手工隐藏,默认文本
Declaration
Objective-C
- (void)fw_showLoading;
-
显示加载吐司,需手工隐藏,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showLoadingWithText:(nullable id)text;
-
显示加载吐司,默认需手工隐藏,指定cancelBlock时会自动隐藏并调用之,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showLoadingWithText:(nullable id)text cancelBlock:(nullable void (^)(void))cancelBlock;
-
隐藏加载吐司
Declaration
Objective-C
- (void)fw_hideLoading;
-
是否正在显示加载吐司
Declaration
Objective-C
@property (nonatomic, readonly) BOOL fw_isShowingLoading;
-
显示进度条吐司,需手工隐藏,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showProgressWithText:(nullable id)text progress:(CGFloat)progress;
-
显示进度条吐司,默认需手工隐藏,指定cancelBlock时会自动隐藏并调用之,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showProgressWithText:(nullable id)text progress:(CGFloat)progress cancelBlock:(nullable void (^)(void))cancelBlock;
-
隐藏进度条吐司
Declaration
Objective-C
- (void)fw_hideProgress;
-
是否正在显示进度条吐司
Declaration
Objective-C
@property (nonatomic, readonly) BOOL fw_isShowingProgress;
-
显示默认样式消息吐司,自动隐藏,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showMessageWithText:(nullable id)text;
-
显示指定样式消息吐司,自动隐藏,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showMessageWithText:(nullable id)text style:(FWToastStyle)style;
-
显示指定样式消息吐司,自动隐藏,自动隐藏完成后回调,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showMessageWithText:(nullable id)text style:(FWToastStyle)style completion:(nullable void (^)(void))completion;
-
显示指定样式消息吐司,可设置自动隐藏和允许交互,自动隐藏完成后回调,支持String和AttributedString
Declaration
Objective-C
- (void)fw_showMessageWithText:(nullable id)text style:(FWToastStyle)style autoHide:(BOOL)autoHide interactive:(BOOL)interactive completion:(nullable void (^)(void))completion;
-
隐藏消息吐司
Declaration
Objective-C
- (void)fw_hideMessage;
-
是否正在显示消息吐司
Declaration
Objective-C
@property (nonatomic, readonly) BOOL fw_isShowingMessage;
-
通用视图绑定数据,改变时自动触发viewModelChanged和FWView.renderData
Declaration
Objective-C
@property (nonatomic, strong, nullable) id fw_viewModel;
-
通用视图数据改变句柄钩子,viewData改变时自动调用
Declaration
Objective-C
@property (nonatomic, copy, nullable) void (^) (__kindof UIView *_Nonnull __strong) fw_viewModelChanged;
-
通用事件接收代理,弱引用,Delegate方式
Declaration
Objective-C
@property (nonatomic, weak, nullable) id<FWViewDelegate> fw_viewDelegate;
-
通用事件接收句柄,Block方式
Declaration
Objective-C
@property (nonatomic, copy, nullable) void (^) (__kindof UIView *_Nonnull __strong, NSNotification *_Nonnull __strong) fw_eventReceived;
-
通用事件完成回调句柄,Block方式
Declaration
Objective-C
@property (nonatomic, copy, nullable) void (^) (__kindof UIView *_Nonnull __strong, NSNotification *_Nonnull __strong) fw_eventFinished;
-
发送指定事件,通知代理,支持附带对象和用户信息
Declaration
Objective-C
- (void)fw_sendEvent:(nonnull NSString *)name;
-
Undocumented
Declaration
Objective-C
- (void)fw_sendEvent:(NSString *)name object:(nullable id)object NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
- (void)fw_sendEvent:(NSString *)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo NS_REFINED_FOR_SWIFT;
-
通知事件完成,自动调用eventFinished句柄和FWView.renderEvent钩子
Declaration
Objective-C
- (void)fw_finishEvent:(nonnull NSNotification *)notification;
-
自定义视图插件,未设置时自动从插件池加载
Declaration
Objective-C
@property (nonatomic, strong, nullable) id<FWViewPlugin> fw_viewPlugin;
-
统一进度视图工厂方法
Declaration
Objective-C
- (nonnull UIView<FWProgressViewPlugin> *)fw_progressViewWithStyle: (FWProgressViewStyle)style;
-
统一指示器视图工厂方法
Declaration
Objective-C
- (nonnull UIView<FWIndicatorViewPlugin> *)fw_indicatorViewWithStyle: (FWIndicatorViewStyle)style;
-
统一进度视图工厂方法
Declaration
Objective-C
+ (nonnull UIView<FWProgressViewPlugin> *)fw_progressViewWithStyle: (FWProgressViewStyle)style;
-
统一指示器视图工厂方法
Declaration
Objective-C
+ (nonnull UIView<FWIndicatorViewPlugin> *)fw_indicatorViewWithStyle: (FWIndicatorViewStyle)style;
-
转场添加到指定控制器(pinEdges占满父视图),返回父容器视图。VC.tabBarController.view > VC.navigationController.view > VC.view
Declaration
Objective-C
- (nonnull UIView *)fw_transitionToController: (nonnull UIViewController *)viewController pinEdges:(BOOL)pinEdges;
-
包装到转场控制器(pinEdges占满父视图),返回创建的控制器
Declaration
Objective-C
- (nonnull UIViewController *)fw_wrappedTransitionController:(BOOL)pinEdges;
-
自定义视图模拟present系统转场(蒙层渐变,内容向上动画)
Declaration
Objective-C
- (void)fw_setPresentTransition:(FWAnimatedTransitionType)transitionType contentView:(nullable UIView *)contentView completion:(nullable void (^)(BOOL))completion;
-
自定义视图模拟alert缩放转场(蒙层渐变,内容缩放动画)
Declaration
Objective-C
- (void)fw_setAlertTransition:(FWAnimatedTransitionType)transitionType completion:(nullable void (^)(BOOL))completion;
-
自定义视图模拟fade渐变转场(蒙层和内容渐变动画)
Declaration
Objective-C
- (void)fw_setFadeTransition:(FWAnimatedTransitionType)transitionType completion:(nullable void (^)(BOOL))completion;
-
将要设置的frame按照view的anchorPoint(.5, .5)处理后再设置,而系统默认按照(0, 0)方式计算
Declaration
Objective-C
@property (nonatomic) CGRect fw_frameApplyTransform;
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat fw_scaleX
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat fw_scaleY
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat fw_translationX
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) CGFloat fw_translationY
-
Undocumented
Declaration
Objective-C
- (void)fw_removeAllSubviews NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
- (nullable __kindof UIView *)fw_subviewOfClass:(Class)clazz NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
- (nullable __kindof UIView *)fw_subviewOfBlock:(BOOL (^)(UIView *view))block NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
- (void)fw_moveToSuperview:(nullable UIView *)view NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly, nullable) UIImage *fw_snapshotImage
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSData *fw_snapshotPdf
-
Undocumented
Declaration
Objective-C
@property (nonatomic) BOOL fw_dragEnabled
-
Undocumented
Declaration
Objective-C
@property (nonatomic, readonly) UIPanGestureRecognizer *fw_dragGesture
-
Undocumented
Declaration
Objective-C
@property (nonatomic) CGRect fw_dragLimit
-
Undocumented
Declaration
Objective-C
@property (nonatomic) CGRect fw_dragArea
-
Undocumented
Declaration
Objective-C
@property (nonatomic) BOOL fw_dragHorizontal
-
Undocumented
Declaration
Objective-C
@property (nonatomic) BOOL fw_dragVertical
-
Undocumented
Declaration
Objective-C
@property (nullable, nonatomic, copy) void (^fw_dragStartedBlock
-
Undocumented
Declaration
Objective-C
@property (nullable, nonatomic, copy) void (^fw_dragMovedBlock
-
Undocumented
Declaration
Objective-C
@property (nullable, nonatomic, copy) void (^fw_dragEndedBlock
-
添加UIView动画,使用默认动画参数
Note
如果动画过程中需要获取进度,可通过添加CADisplayLink访问self.layer.presentationLayer获取,下同
Declaration
Objective-C
- (void)fw_addAnimationWithBlock:(nonnull void (^)(void))block completion:(nullable void (^)(BOOL))completion;
Parameters
block
动画代码块
completion
完成事件
-
添加UIView动画
Declaration
Objective-C
- (void)fw_addAnimationWithBlock:(nonnull void (^)(void))block duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
block
动画代码块
duration
持续时间
completion
完成事件
-
添加UIView动画
Declaration
Objective-C
- (void)fw_addAnimationWithCurve:(UIViewAnimationCurve)curve transition:(UIViewAnimationTransition)transition duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
curve
动画速度
transition
动画类型
duration
持续时间,默认0.2
completion
完成事件
-
添加CABasicAnimation动画
Declaration
Objective-C
- (nonnull CABasicAnimation *) fw_addAnimationWithKeyPath:(nonnull NSString *)keyPath fromValue:(nonnull id)fromValue toValue:(nonnull id)toValue duration:(CFTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
keyPath
动画路径
fromValue
开始值
toValue
结束值
duration
持续时间,0为默认(0.25秒)
completion
完成事件
Return Value
CABasicAnimation
-
添加转场动画
Declaration
Objective-C
- (void)fw_addTransitionWithOption:(UIViewAnimationOptions)option block:(nonnull void (^)(void))block duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
option
动画选项
block
动画代码块
duration
持续时间
completion
完成事件
-
添加转场动画,可指定animationsEnabled,一般用于window切换rootViewController
Declaration
Objective-C
- (void)fw_addTransitionWithOption:(UIViewAnimationOptions)option block:(nonnull void (^)(void))block duration:(NSTimeInterval)duration animationsEnabled:(BOOL)animationsEnabled completion:(nullable void (^)(BOOL))completion;
Parameters
option
动画选项
block
动画代码块
duration
持续时间
animationsEnabled
是否启用动画
completion
完成事件
-
添加转场动画
Declaration
Objective-C
- (void)fw_addTransitionToView:(nonnull UIView *)toView withOption:(UIViewAnimationOptions)option duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
toView
目标视图
option
动画选项
duration
持续时间
completion
完成事件
-
添加CATransition转场动画 备注:移除动画可调用[self fwRemoveAnimation]
Declaration
Objective-C
- (nonnull CATransition *) fw_addTransitionWithType:(nonnull NSString *)type subtype:(nullable NSString *)subtype timingFunction:(nullable NSString *)timingFunction duration:(CFTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
type
动画类型
subtype
子类型
timingFunction
动画速度
duration
持续时间,0为默认(0.25秒)
completion
完成事件
Return Value
CATransition
-
移除单个框架视图动画
Declaration
Objective-C
- (void)fw_removeAnimation;
-
移除所有视图动画
Declaration
Objective-C
- (void)fw_removeAllAnimations;
-
绘制动画
Declaration
Objective-C
- (nonnull CABasicAnimation *)fw_strokeWithLayer:(nonnull CAShapeLayer *)layer duration:(NSTimeInterval)duration completion: (nullable void (^)(BOOL))completion;
Parameters
layer
CAShapeLayer层
duration
持续时间
completion
完成回调
Return Value
CABasicAnimation
-
水平摇摆动画
Declaration
Objective-C
- (void)fw_shakeWithTimes:(NSInteger)times delta:(CGFloat)delta duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
times
摇摆次数,默认10
delta
摇摆宽度,默认5
duration
单次时间,默认0.03
completion
完成回调
-
渐显隐动画
Declaration
Objective-C
- (void)fw_fadeWithAlpha:(float)alpha duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
alpha
透明度
duration
持续时长
completion
完成回调
-
渐变代码块动画
Declaration
Objective-C
- (void)fw_fadeWithBlock:(nonnull void (^)(void))block duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
block
动画代码块,比如调用imageView.setImage:方法
duration
持续时长,建议0.5
completion
完成回调
-
旋转动画
Declaration
Objective-C
- (void)fw_rotateWithDegree:(CGFloat)degree duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
degree
旋转度数,备注:逆时针需设置-179.99。使用CAAnimation无此问题
duration
持续时长
completion
完成回调
-
缩放动画
Declaration
Objective-C
- (void)fw_scaleWithScaleX:(float)scaleX scaleY:(float)scaleY duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
scaleX
X轴缩放率
scaleY
Y轴缩放率
duration
持续时长
completion
完成回调
-
移动动画
Declaration
Objective-C
- (void)fw_moveWithPoint:(CGPoint)point duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
point
目标点
duration
持续时长
completion
完成回调
-
移动变化动画
Declaration
Objective-C
- (void)fw_moveWithFrame:(CGRect)frame duration:(NSTimeInterval)duration completion:(nullable void (^)(BOOL))completion;
Parameters
frame
目标区域
duration
持续时长
completion
完成回调
-
取消动画效果执行block
Declaration
Objective-C
+ (void)fw_animateNoneWithBlock:(nonnull void (^)(void))block;
Parameters
block
动画代码块
-
取消动画效果执行block
Declaration
Objective-C
+ (void)fw_animateNoneWithBlock:(nonnull void (^)(void))block completion:(nullable void (^)(void))completion;
Parameters
block
动画代码块
completion
完成事件
-
执行block动画完成后执行指定回调
Declaration
Objective-C
+ (void)fw_animateWithBlock:(nonnull void (^)(void))block completion:(nullable void (^)(void))completion;
Parameters
block
动画代码块
completion
完成事件
-
设置毛玻璃效果,使用UIVisualEffectView。内容需要添加到UIVisualEffectView.contentView
Declaration
Objective-C
- (nullable UIVisualEffectView *)fw_setBlurEffect:(UIBlurEffectStyle)style;
Parameters
style
毛玻璃效果样式
-
绘制形状路径,需要在drawRect中调用
Declaration
Objective-C
- (void)fw_drawBezierPath:(nonnull UIBezierPath *)bezierPath strokeWidth:(CGFloat)strokeWidth strokeColor:(nonnull UIColor *)strokeColor fillColor:(nullable UIColor *)fillColor;
Parameters
bezierPath
绘制路径
strokeWidth
绘制宽度
strokeColor
绘制颜色
fillColor
填充颜色
-
绘制渐变颜色,需要在drawRect中调用,支持四个方向,默认向下Down
Declaration
Objective-C
- (void)fw_drawLinearGradient:(CGRect)rect colors:(nonnull NSArray *)colors locations:(nullable const CGFloat *)locations direction:(UISwipeGestureRecognizerDirection)direction;
Parameters
rect
绘制区域
colors
渐变颜色,CGColor数组,如:@[(bridge id)[UIColor redColor].CGColor, (bridge id)[UIColor blueColor].CGColor]
locations
渐变位置,传NULL时均分,如:CGFloat locations[] = {0.0, 1.0};
direction
渐变方向,自动计算startPoint和endPoint,支持四个方向,默认向下Down
-
绘制渐变颜色,需要在drawRect中调用
Declaration
Objective-C
- (void)fw_drawLinearGradient:(CGRect)rect colors:(nonnull NSArray *)colors locations:(nullable const CGFloat *)locations startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;
Parameters
rect
绘制区域
colors
渐变颜色,CGColor数组,如:@[(bridge id)[UIColor redColor].CGColor, (bridge id)[UIColor blueColor].CGColor]
locations
渐变位置,传NULL时均分,如:CGFloat locations[] = {0.0, 1.0};
startPoint
渐变开始点,需要根据rect计算
endPoint
渐变结束点,需要根据rect计算
-
添加渐变Layer
Declaration
Objective-C
- (nonnull CAGradientLayer *) fw_addGradientLayer:(CGRect)frame colors:(nonnull NSArray *)colors locations:(nullable NSArray<NSNumber *> *)locations startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint;
Parameters
frame
渐变区域
colors
渐变颜色,CGColor数组,如[黑,白,黑]
locations
渐变位置,0~1,如[0.25, 0.5, 0.75]对应颜色为[0-0.25黑,0.25-0.5黑渐变白,0.5-0.75白渐变黑,0.75-1黑]
startPoint
渐变开始点,设置渐变方向,左上点为(0,0),右下点为(1,1)
endPoint
渐变结束点
Return Value
渐变Layer
-
Undocumented
Declaration
Objective-C
- (CAShapeLayer *)fw_addCircleLayer:(CGRect)rect degree:(CGFloat)degree progress:(CGFloat)progress strokeColor:(UIColor *)strokeColor strokeWidth:(CGFloat)strokeWidth NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
- (CAShapeLayer *)fw_addCircleLayer:(CGRect)rect degree:(CGFloat)degree progress:(CGFloat)progress progressColor:(UIColor *)progressColor strokeColor:(UIColor *)strokeColor strokeWidth:(CGFloat)strokeWidth NS_REFINED_FOR_SWIFT;
-
Undocumented
Declaration
Objective-C
- (CALayer *)fw_addCircleLayer:(CGRect)rect degree:(CGFloat)degree progress:(CGFloat)progress gradientBlock:(nullable void (^)(CALayer *layer))gradientBlock strokeColor:(UIColor *)strokeColor strokeWidth:(CGFloat)strokeWidth NS_REFINED_FOR_SWIFT;
-
添加虚线Layer
Declaration
Objective-C
- (nonnull CALayer *)fw_addDashLayer:(CGRect)rect lineLength:(CGFloat)lineLength lineSpacing:(CGFloat)lineSpacing lineColor:(nonnull UIColor *)lineColor;
Parameters
rect
虚线区域,从中心绘制
lineLength
虚线的宽度
lineSpacing
虚线的间距
lineColor
虚线的颜色
Return Value
虚线Layer
-
获取当前 UIView 层级树信息
Declaration
Objective-C
@property (nonatomic, copy, readonly) NS_REFINED_FOR_SWIFT NSString *fw_viewInfo;
-
是否需要添加debug背景色,默认NO
Declaration
Objective-C
@property (nonatomic) BOOL fw_showDebugColor;
-
是否每个view的背景色随机,如果不随机则统一使用半透明红色,默认NO
Declaration
Objective-C
@property (nonatomic) BOOL fw_randomDebugColor;
-
是否需要添加debug边框,默认NO
Declaration
Objective-C
@property (nonatomic) BOOL fw_showDebugBorder;
-
指定debug边框的颜色,默认半透明红色
Declaration
Objective-C
@property (nonatomic, strong) NS_REFINED_FOR_SWIFT UIColor *fw_debugBorderColor;
-
显示骨架屏,指定布局代理
Declaration
Swift
@objc(fw_showSkeletonWithDelegate:) open func __fw_showSkeleton(delegate: SkeletonViewDelegate?)
-
显示骨架屏,指定布局句柄
Declaration
Swift
@objc(fw_showSkeletonWithBlock:) open func __fw_showSkeleton(block: ((SkeletonLayout) -> Void)?)
-
显示骨架屏,默认布局代理为self
Declaration
Swift
@objc(fw_showSkeleton) open func __fw_showSkeleton()
-
隐藏骨架屏
Declaration
Swift
@objc(fw_hideSkeleton) open func __fw_hideSkeleton()
-
是否正在显示骨架屏
Declaration
Swift
@objc(fw_hasSkeleton) open var __fw_hasSkeleton: Bool { get }