Skip to content

Commit

Permalink
Fixed Tencent#623 修复 QMUILabel 先开启 canPerformCopyAction 再设置 backgroun…
Browse files Browse the repository at this point in the history
…dColor,会导致复制 menu 消失后背景色丢失的 bug
  • Loading branch information
MoLice committed Jun 17, 2019
1 parent 2f8dc48 commit 9d00dc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions QMUIKit/QMUIComponents/QMUILabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
/// 当 canPerformCopyAction 开启时,长按出来的菜单上的复制按钮的文本,默认为 nil,nil 时 menuItem 上的文字为“复制”
@property(nonatomic, copy) IBInspectable NSString *menuItemTitleForCopyAction;

/// 如果打开了`canPerformCopyAction`,则长按时背景色将会被改为`highlightedBackgroundColor`
@property(nonatomic,strong) IBInspectable UIColor *highlightedBackgroundColor;
/// 如果打开了`canPerformCopyAction`,则长按时背景色将会被改为`highlightedBackgroundColor`,默认值为 nil
@property(nonatomic,strong) IBInspectable UIColor *highlightedBackgroundColor UI_APPEARANCE_SELECTOR;

/// 点击了“复制”后的回调
@property(nonatomic, copy) void (^didCopyBlock)(QMUILabel *label, NSString *stringCopied);
Expand Down
18 changes: 4 additions & 14 deletions QMUIKit/QMUIComponents/QMUILabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ - (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:rect];
}

- (void)setHighlightedBackgroundColor:(UIColor *)highlightedBackgroundColor {
_highlightedBackgroundColor = highlightedBackgroundColor;

if (highlightedBackgroundColor) {
self.originalBackgroundColor = self.backgroundColor;
}
}

- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];

Expand All @@ -87,10 +79,6 @@ - (void)setCanPerformCopyAction:(BOOL)canPerformCopyAction {
[self addGestureRecognizer:self.longGestureRecognizer];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMenuWillHideNotification:) name:UIMenuControllerWillHideMenuNotification object:nil];

if (!self.highlightedBackgroundColor) {
self.highlightedBackgroundColor = TableViewCellSelectedBackgroundColor; // 设置个默认值
}
} else if (!_canPerformCopyAction && self.longGestureRecognizer) {
[self removeGestureRecognizer:self.longGestureRecognizer];
self.longGestureRecognizer = nil;
Expand Down Expand Up @@ -136,9 +124,11 @@ - (void)handleLongPressGestureRecognizer:(UIGestureRecognizer *)gestureRecognize
[menuController setTargetRect:self.frame inView:self.superview];
[menuController setMenuVisible:YES animated:YES];

[self setHighlighted:YES];
if (self.highlightedBackgroundColor) self.originalBackgroundColor = self.backgroundColor;

self.highlighted = YES;
} else if (gestureRecognizer.state == UIGestureRecognizerStatePossible) {
[self setHighlighted:NO];
self.highlighted = NO;
}
}

Expand Down

0 comments on commit 9d00dc0

Please sign in to comment.