gate baseControlTouchEvent:self];
}
if (self.buttonEvent && self.target) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self.target performSelector:self.buttonEvent withObject:self];
#pragma clang diagnostic pop
}
}
- (void)touchDragExit {
if (_enableEvent == NO) {
return;
}
[self changeToState:BaseControlStateNormal animated:YES];
}
- (void)touchBegin {
if (_enableEvent == NO) {
return;
}
[self changeToState:BaseControlStateHighlighted animated:YES];
}
#pragma mark -
- (void)changeToState:(BaseControlState)state animated:(BOOL)animated {
_state = state;
if (state == BaseControlStateNormal) {
_enableEvent = YES;
[self normalStateAnimated:animated];
} else if (state == BaseControlStateHighlighted) {
_enableEvent = YES;
[self highlightedAnimated:animated];
} else if (state == BaseControlStateDisabled) {
_enableEvent = NO;
[self disabledAnimated:animated];
}
}
- (void)normalStateAnimated:(BOOL)animated {
if (!animated) {
self.normalLabel.alpha = 1.f;
self.highlightedLabel.alpha = 0.f;
self.disabledLabel.alpha = 0.f;
self.backgroundView.backgroundColor = self.normalBackgroundColor;
} else {
[UIView animateWithDuration:0.25f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.normalLabel.alpha = 1.f;
self.highlightedLabel.alpha = 0.f;
self.disabledLabel.alpha = 0.f;
self.backgroundView.backgroundColor = self.normalBackgroundColor;
} completion:nil];
}
}
- (void)highlightedAnimated:(BOOL)animated {
if (!animated) {
self.normalLabel.alpha = 0.f;
self.highlightedLabel.alpha = 1.f;
self.disabledLabel.alpha = 0.f;
self.backgroundView.backgroundColor = self.highlightBackgroundColor;
} else {
[UIView animateWithDuration:0.25f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.normalLabel.alpha = 0.f;
self.highlightedLabel.alpha = 1.f;
self.disabledLabel.alpha = 0.f;
self.backgroundView.backgroundColor = self.highlightBackgroundColor;
} completion:nil];
}
}
- (void)disabledAnimated:(BOOL)animated {
if (!animated) {
self.normalLabel.alpha = 0.f;
self.highlightedLabel.alpha = 0.f;
self.disabledLabel.alpha = 1.f;
self.backgroundView.backgroundColor = self.disabledBackgroundColor;
} else {
[UIView animateWithDuration:0.25f delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
self.normalLabel.alpha = 0.f;
self.highlightedLabel.alpha = 0.f;
self.disabledLabel.alpha = 1.f;
self.backgroundView.backgroundColor = self.disabledBackgroundColor;
} completion:nil];
}
}
#pragma mark - 重写getter,setter方法
- (void)setTitle:(NSString *)title {
_title = title;
self.normalLabel.text = title;
self.highlightedLabel.text = title;
self.disabledLabel.text = title;
}
- (void)setTextAlignment:(NSTextAlignment)textAlignment {
_textAlignment = textAlignment;
self.normalLabel.textAlignment = textAlignment;
self.highlightedLabel.textAlignment = textAlignment;
self.disabledLabel.textAlignment = textAlignment;
}
- (void)setFon |