Skip to content

Instantly share code, notes, and snippets.

View faimin's full-sized avatar
👻
learning

Zero.D.Saber faimin

👻
learning
View GitHub Profile
@faimin
faimin / UIView+ZDShake
Created May 16, 2017 02:58
a UIView category for shaking
- (void)zd_shake:(CGFloat)range {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.duration = 0.5;
animation.values = @[@(-range), @(range), @(-range/2), @(range/2), @(-range/5), @(range/5), @(0)];
animation.repeatCount = CGFLOAT_MAX;
[self.layer addAnimation:animation forKey:@"shake"];
}
@faimin
faimin / UIView+ZDCalculateDynamicHeight
Created May 16, 2017 02:54
a UIView category for calculateDynamicHeight
- (CGFloat)calculateDynamicHeightWithMaxWidth:(CGFloat)maxWidth {
self.translatesAutoresizingMaskIntoConstraints = NO;
CGFloat viewMaxWidth = maxWidth ? : CGRectGetWidth([UIScreen mainScreen].bounds);
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:viewMaxWidth];
[self addConstraint:widthConstraint];
CGSize fittingSize = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
[self removeConstraint:widthConstraint];
return fittingSize.height;