iOS开发 ios零碎记录

UITextField的占位符抖动效果

2015-11-04  本文已影响286人  武小寺
-(instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.font = [UIFont systemFontOfSize:14];
    }
    return self;
}
-(UILabel *)gtPlaceholderLabel
{
    return [self valueForKey:@"_placeholderLabel"];
}
-(UILabel *)gtDisplayLabel
{
    return [self valueForKey:@"_displayLabel"];
}
//复写父类的方法
-(BOOL)becomeFirstResponder
{
    if (self.normalColor == nil) {
        self.normalColor = self.gtPlaceholderLabel.textColor;
    }if (self.selectedColor == nil) {
        self.selectedColor = self.gtPlaceholderLabel.textColor;
    }
    self.gtPlaceholderLabel.textColor = self.selectedColor;
    [self placeholderLabelDoAnimationWithType:self.gtAnimationType];
    return [super becomeFirstResponder];
}
-(BOOL)resignFirstResponder
{
    switch (self.gtAnimationType) {
        case GTAnimationTypeUpDown:{
            self.gtPlaceholderLabel.transform = CGAffineTransformIdentity;
        }
            break;
        case GTAnimationTypeLeftRight:{
           self.gtPlaceholderLabel.transform = CGAffineTransformIdentity;
        }
            break;
        case GTAnimationTypeBlowUp:{
            
        }
            break;
        case GTAnimationTypeEasyInOut:{
            [UIView animateWithDuration:0.5 animations:^{
                self.gtPlaceholderLabel.alpha = 1;
            }];
        }
            break;
        case GTAnimationTypeNone:{
            break;
        }
            break;
        default:
            break;
    }
    
    self.gtPlaceholderLabel.textColor = self.normalColor;
    return [super resignFirstResponder];
}

代码地址: https://github.com/WWLJ/AnimationTextField.git
参考来源: http://www.jianshu.com/p/8a73e4e2664e

上一篇下一篇

猜你喜欢

热点阅读