按钮 跳动和点击动画

#import "WatchViewController.h"
#import "StickButton.h"
@interface WatchViewController ()
@property (nonatomic ,assign) int btnIndex;
@property (nonatomic ,retain) NSMutableArray *itemButtons;
@property (nonatomic ,retain) NSTimer *timer;
@end

@implementation WatchViewController
- (NSMutableArray*)itemButtons
{
    if (!_itemButtons)
    {
        _itemButtons = [NSMutableArray array];
    }
    return _itemButtons;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setUpAllBtn];
    
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];

}
- (void)timeChange
{
    if (_btnIndex == self.itemButtons.count)
    {
        [_timer invalidate];
        return;
    }
    UIButton *button = self.itemButtons[_btnIndex];
    [self setUpOneButtonAnimate:button];
    _btnIndex ++;
    
}
- (void)setUpOneButtonAnimate:(UIButton *)button
{
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        
        button.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        
    }];
}
- (void)setUpAllBtn
{
    int cols = 3;
    int col = 0;
    int row = 0;
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat wh = 100;
    CGFloat margin = ([UIScreen mainScreen].bounds.size.width - cols * wh)/(cols + 1);
    CGFloat oriY = 300;
    NSArray*titleArr=@[@"日用百货",@"家用电器",@"数字乡镇",@"绿色食品",@"女士专区",@"男士专区"];
    
    for (int i=0; i

自定义按钮

#import "StickButton.h"

@interface StickButton ()

@end

@implementation StickButton


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setUp];
    }
    return self;
}
- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setUp];
}
- (void)setUp
{
    self.imageView.contentMode = UIViewContentModeCenter;
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
}
// 以后如果通过代码设置子控件的位置,一般都是在layoutSubviews里面去写
//layoutSubviews :只要父控件的frame一改变就会调用layoutSubviews,重新布局子控件
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat W = self.bounds.size.width;
    CGFloat imageH = self.bounds.size.height * 0.8;
    
    self.imageView.frame = CGRectMake(0, 0, W, imageH);
    
    CGFloat labelH = self.bounds.size.height - imageH;
    self.titleLabel.frame = CGRectMake(0, imageH, W, labelH);
}
- (void)setHighlighted:(BOOL)highlighted
{
    
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.5 animations:^{
        self.transform = CGAffineTransformMakeScale(2.0, 2.0);
        self.alpha = 0.0;
    }];
    
}
@end
按钮 跳动和点击动画_第1张图片
147A547F-8349-4E9E-8B4D-141562FA41FC.png
按钮 跳动和点击动画_第2张图片
3F62D8B1-132C-4238-BF25-A8D633C00334.png
按钮 跳动和点击动画_第3张图片
EF2B24C9-5094-4DE2-8BAD-9DEB4D58E2EE.png
按钮 跳动和点击动画_第4张图片
FF34014B-F4AB-408D-9196-D1CBC5D9A5FC.png
按钮 跳动和点击动画_第5张图片
EC47633A-FE59-459B-B4E7-3B74B06C944F.png

你可能感兴趣的:(按钮 跳动和点击动画)