设为首页 加入收藏

TOP

用动画切换按钮的状态(三)
2017-10-13 10:28:45 】 浏览:6911
Tags:动画 切换 按钮 状态
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
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【原】iOS学习之KVC原理 下一篇【代码笔记】iOS-设置textView或..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目