弹性动画--哟底部弹出俩球
2018-06-06 本文已影响11人
Luyc_Han
Untitled.gif
//
// ViewController.m
// dongjifen
//
// Created by 王木木 on 2018/6/6.
// Copyright © 2018年 wangmumu. All rights reserved.
//
#define sheight [UIScreen mainScreen].bounds.size.height
#define swidth [UIScreen mainScreen].bounds.size.width
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UILabel *dotView;
@property (nonatomic,strong) UILabel *dotView1;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
button.backgroundColor = [UIColor redColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(touchbutton) forControlEvents:UIControlEventTouchUpInside];
self.dotView = [[UILabel alloc] init];
self.dotView.text = @"111";
self.dotView.backgroundColor = [UIColor brownColor];
self.dotView.frame = CGRectMake((swidth-50)/2, sheight, 50, 50);
self.dotView.layer.cornerRadius = 25;
self.dotView.layer.masksToBounds = YES;
[self.view addSubview:self.dotView];
self.dotView1 = [[UILabel alloc] init];
self.dotView1.backgroundColor = [UIColor brownColor];
self.dotView1.text = @"111";
self.dotView1.frame = CGRectMake((swidth-50)/2, sheight, 50, 50);
self.dotView1.layer.cornerRadius = 25;
self.dotView1.layer.masksToBounds = YES;
[self.view addSubview:self.dotView1];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:1
initialSpringVelocity:30
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.dotView.frame = CGRectMake((swidth-50)/2 - 50, sheight/2, 50, 50);
}
completion:^(BOOL finished) {
}
];
[UIView animateWithDuration:0.5
delay:0.1
usingSpringWithDamping:1
initialSpringVelocity:30
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.dotView1.frame = CGRectMake((swidth-50)/2 + 50, sheight/2, 50, 50);
}
completion:^(BOOL finished) {
}
];
}
- (void)touchbutton {
[UIView animateWithDuration:1
delay:0
usingSpringWithDamping:50
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
self.dotView.frame = CGRectMake((swidth-50)/2, sheight, 50, 50);
}
completion:^(BOOL finished) {
}
];
[UIView animateWithDuration:1
delay:0.1
usingSpringWithDamping:50
initialSpringVelocity:0
options:UIViewAnimationOptionCurveLinear
animations:^{
self.dotView1.frame = CGRectMake((swidth-50)/2, sheight, 50, 50);
}
completion:^(BOOL finished) {
}
];
}
@end