iOS: fix the loss of Corner effect caused by tableViewCell reuse.
This commit is contained in:
parent
7bc22c6c1f
commit
8c52fe5265
@ -20,7 +20,6 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <CoreGraphics/CoreGraphics.h>
|
#import <CoreGraphics/CoreGraphics.h>
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <QuartzCore/QuartzCore.h>
|
|
||||||
|
|
||||||
typedef UIEdgeInsets DoricMargin;
|
typedef UIEdgeInsets DoricMargin;
|
||||||
typedef UIEdgeInsets DoricPadding;
|
typedef UIEdgeInsets DoricPadding;
|
||||||
@ -123,8 +122,3 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
|||||||
@property(nonatomic, strong) DoricLayout *doricLayout;
|
@property(nonatomic, strong) DoricLayout *doricLayout;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface DoricShapeLayer : CAShapeLayer
|
|
||||||
@property CGRect viewBounds;
|
|
||||||
@property UIEdgeInsets corners;
|
|
||||||
@end
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
#import "UIView+Doric.h"
|
#import "UIView+Doric.h"
|
||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
|
#import <QuartzCore/QuartzCore.h>
|
||||||
|
|
||||||
void DoricAddEllipticArcPath(CGMutablePathRef path,
|
void DoricAddEllipticArcPath(CGMutablePathRef path,
|
||||||
CGPoint origin,
|
CGPoint origin,
|
||||||
@ -61,8 +62,12 @@ CGPathRef DoricCreateRoundedRectPath(CGRect bounds,
|
|||||||
|
|
||||||
static const void *kLayoutConfig = &kLayoutConfig;
|
static const void *kLayoutConfig = &kLayoutConfig;
|
||||||
|
|
||||||
@implementation DoricShapeLayer
|
@interface DoricShapeLayer : CAShapeLayer
|
||||||
|
@property CGRect viewBounds;
|
||||||
|
@property UIEdgeInsets corners;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation DoricShapeLayer
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation UIView (DoricLayout)
|
@implementation UIView (DoricLayout)
|
||||||
@ -255,20 +260,21 @@ - (void)setFrame {
|
|||||||
originFrame = CGRectApplyAffineTransform(originFrame, self.view.transform);
|
originFrame = CGRectApplyAffineTransform(originFrame, self.view.transform);
|
||||||
originFrame = CGRectOffset(originFrame, anchor.x * self.measuredWidth + self.measuredX, anchor.y * self.measuredHeight + self.measuredY);
|
originFrame = CGRectOffset(originFrame, anchor.x * self.measuredWidth + self.measuredX, anchor.y * self.measuredHeight + self.measuredY);
|
||||||
}
|
}
|
||||||
if (![self rect:originFrame equalTo:self.view.frame]) {
|
BOOL isFrameChange = ![self rect:originFrame equalTo:self.view.frame];
|
||||||
|
if (isFrameChange) {
|
||||||
self.view.frame = originFrame;
|
self.view.frame = originFrame;
|
||||||
}
|
}
|
||||||
if (!UIEdgeInsetsEqualToEdgeInsets(self.corners, UIEdgeInsetsZero)) {
|
if (!UIEdgeInsetsEqualToEdgeInsets(self.corners, UIEdgeInsetsZero)) {
|
||||||
if (self.view.layer.mask) {
|
if (self.view.layer.mask) {
|
||||||
if ([self.view.layer.mask isKindOfClass:[DoricShapeLayer class]]) {
|
if ([self.view.layer.mask isKindOfClass:[DoricShapeLayer class]]) {
|
||||||
DoricShapeLayer *shapeLayer = (DoricShapeLayer *)self.view.layer.mask;
|
DoricShapeLayer *shapeLayer = (DoricShapeLayer *)self.view.layer.mask;
|
||||||
if (![self compareCornersValue:shapeLayer.corners withCorners:self.corners]
|
if (!UIEdgeInsetsEqualToEdgeInsets(self.corners, shapeLayer.corners)
|
||||||
|| !CGRectEqualToRect(self.view.bounds, shapeLayer.viewBounds)) {
|
|| !CGRectEqualToRect(self.view.bounds, shapeLayer.viewBounds)) {
|
||||||
shapeLayer.corners = self.corners;
|
shapeLayer.corners = self.corners;
|
||||||
shapeLayer.viewBounds = self.view.bounds;
|
shapeLayer.viewBounds = self.view.bounds;
|
||||||
[self configMaskWithLayer:shapeLayer];
|
[self configMaskWithLayer:shapeLayer];
|
||||||
}
|
}
|
||||||
} else if (![self rect:originFrame equalTo:self.view.frame]) {
|
} else if (isFrameChange) {
|
||||||
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
|
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
|
||||||
[self configMaskWithLayer:shapeLayer];
|
[self configMaskWithLayer:shapeLayer];
|
||||||
}
|
}
|
||||||
@ -305,16 +311,6 @@ - (void)configMaskWithLayer:(CAShapeLayer *)shapeLayer {
|
|||||||
self.view.layer.mask = shapeLayer;
|
self.view.layer.mask = shapeLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)compareCornersValue:(UIEdgeInsets)corners1 withCorners:(UIEdgeInsets)corners2 {
|
|
||||||
if (corners1.top == corners2.top
|
|
||||||
&& corners1.left == corners2.left
|
|
||||||
&& corners1.right == corners2.right
|
|
||||||
&& corners1.bottom == corners2.bottom) {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)measureUndefinedContent:(CGSize)targetSize {
|
- (void)measureUndefinedContent:(CGSize)targetSize {
|
||||||
CGSize measuredSize = [self.view sizeThatFits:targetSize];
|
CGSize measuredSize = [self.view sizeThatFits:targetSize];
|
||||||
if (self.widthSpec == DoricLayoutFit) {
|
if (self.widthSpec == DoricLayoutFit) {
|
||||||
@ -634,3 +630,4 @@ - (void)layoutHLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user