iOS

    xiaoxiao2025-02-25  23

    https://github.com/facebook/pop

    推荐使用pod导入

    1、按钮动画 1

    #import <UIKit/UIKit.h> @interface FlatButton : UIButton + (instancetype)button; @end

    #import "FlatButton.h" #import <POP/POP.h> @interface FlatButton() - (void)setup; - (void)scaleToSmall; - (void)scaleAnimation; - (void)scaleToDefault; @end @implementation FlatButton + (instancetype)button { return [self buttonWithType:UIButtonTypeCustom]; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } #pragma mark - Instance methods - (UIEdgeInsets)titleEdgeInsets { return UIEdgeInsetsMake(4.f, 28.f, 4.f, 28.f); } - (CGSize)intrinsicContentSize { CGSize s = [super intrinsicContentSize]; return CGSizeMake(s.width + self.titleEdgeInsets.left + self.titleEdgeInsets.right, s.height + self.titleEdgeInsets.top + self.titleEdgeInsets.bottom); } #pragma mark - Private instance methods - (void)setup { self.backgroundColor = self.tintColor; self.layer.cornerRadius = 4.f; [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; self.titleLabel.font = [UIFont fontWithName:@"Avenir-Medium" size:22]; [self addTarget:self action:@selector(scaleToSmall) forControlEvents:UIControlEventTouchDown | UIControlEventTouchDragEnter]; [self addTarget:self action:@selector(scaleAnimation) forControlEvents:UIControlEventTouchUpInside]; [self addTarget:self action:@selector(scaleToDefault) forControlEvents:UIControlEventTouchDragExit]; } - (void)scaleToSmall { POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(0.95f, 0.95f)]; [self.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSmallAnimation"]; } - (void)scaleAnimation { POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; scaleAnimation.velocity = [NSValue valueWithCGSize:CGSizeMake(3.f, 3.f)]; scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.f)]; scaleAnimation.springBounciness = 18.0f; [self.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleSpringAnimation"]; } - (void)scaleToDefault { POPBasicAnimation *scaleAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(1.f, 1.f)]; [self.layer pop_addAnimation:scaleAnimation forKey:@"layerScaleDefaultAnimation"]; } @end
    转载请注明原文地址: https://ju.6miu.com/read-1296626.html
    最新回复(0)