iOS可复用控件之发送动画
2017-10-13 16:08
246 查看
GitHub地址:https://github.com/runThor/HTSendAnimation
效果:
这里向上轻扫信封会出现信封旋转着向远处飞出的效果。
实现:
// HTSendAnimation.m
#import "HTSendAnimation.h"
@interface HTSendAnimation ()
@property (nonatomic, strong) UIImageView *imageView; // 主体图片
@property (nonatomic, strong) UIImageView *circle1; // 圆点1
@property (nonatomic, strong) UIImageView *circle2; // 圆点2
@property (nonatomic, strong) UIImageView *circle3; // 圆点3
@end
@implementation HTSendAnimation
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// 初始化视图
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0.5 * SCREEN_WIDTH, 0.4 * SCREEN_WIDTH)];
[self.imageView setCenter:CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT - self.imageView.frame.size.height)];
self.imageView.image = [UIImage imageNamed:@"envelope"];
self.imageView.userInteractionEnabled = YES;
[self addSubview:self.imageView];
// 设置向上轻扫手势触发事件
UISwipeGestureRecognizer *swipeGes = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeGes)];
swipeGes.direction = UISwipeGestureRecognizerDirectionUp;
[self.imageView addGestureRecognizer:swipeGes];
// 点击移除发送视图
UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeSelf)];
[self addGestureRecognizer:tapGes];
self.circle1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"deepBlue"]];
self.circle1.center = CGPointMake(self.imageView.center.x, self.imageView.frame.origin.y - 50);
self.circle1.bounds = CGRectMake(0, 0, 20, 20);
[self addSubview:self.circle1];
self.circle2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lightBlue"]];
self.circle2.center = CGPointMake(self.imageView.center.x, self.circle1.frame.origin.y - 50);
self.circle2.bounds = CGRectMake(0, 0, 15, 15);
[self addSubview:self.circle2];
self.circle3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lightBlue"]];
self.circle3.center = CGPointMake(self.imageView.center.x, self.circle2.frame.origin.y - 50);
self.circle3.bounds = CGRectMake(0, 0, 10, 10);
[self addSubview:self.circle3];
}
return self;
}
// 向上轻扫事件
- (void)didSwipeGes {
// 移除圆点
[self.circle1 removeFromSuperview];
[self.circle2 removeFromSuperview];
[self.circle3 removeFromSuperview];
// 旋转并缩小,直至消失
[UIView animateWithDuration:1.5 animations:^{
self.imageView.frame = CGRectMake(SCREEN_WIDTH/2, 0, 0, 0);
self.imageView.transform = CGA
4000
ffineTransformMakeRotation(179);
self.imageView.transform = CGAffineTransformMakeRotation(358);
} completion:^(BOOL finished) {
[self removeSelf];
}];
}
// 移除发送视图
- (void)removeSelf {
[self removeFromSuperview];
}
@end
使用:
// ViewController.m
#import "ViewController.h"
#import "HTSendAnimation.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
HTSendAnimation *sendView = [[HTSendAnimation alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
sendView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
[self.view addSubview:sendView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
效果:
这里向上轻扫信封会出现信封旋转着向远处飞出的效果。
实现:
// HTSendAnimation.m
#import "HTSendAnimation.h"
@interface HTSendAnimation ()
@property (nonatomic, strong) UIImageView *imageView; // 主体图片
@property (nonatomic, strong) UIImageView *circle1; // 圆点1
@property (nonatomic, strong) UIImageView *circle2; // 圆点2
@property (nonatomic, strong) UIImageView *circle3; // 圆点3
@end
@implementation HTSendAnimation
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// 初始化视图
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0.5 * SCREEN_WIDTH, 0.4 * SCREEN_WIDTH)];
[self.imageView setCenter:CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT - self.imageView.frame.size.height)];
self.imageView.image = [UIImage imageNamed:@"envelope"];
self.imageView.userInteractionEnabled = YES;
[self addSubview:self.imageView];
// 设置向上轻扫手势触发事件
UISwipeGestureRecognizer *swipeGes = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeGes)];
swipeGes.direction = UISwipeGestureRecognizerDirectionUp;
[self.imageView addGestureRecognizer:swipeGes];
// 点击移除发送视图
UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeSelf)];
[self addGestureRecognizer:tapGes];
self.circle1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"deepBlue"]];
self.circle1.center = CGPointMake(self.imageView.center.x, self.imageView.frame.origin.y - 50);
self.circle1.bounds = CGRectMake(0, 0, 20, 20);
[self addSubview:self.circle1];
self.circle2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lightBlue"]];
self.circle2.center = CGPointMake(self.imageView.center.x, self.circle1.frame.origin.y - 50);
self.circle2.bounds = CGRectMake(0, 0, 15, 15);
[self addSubview:self.circle2];
self.circle3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lightBlue"]];
self.circle3.center = CGPointMake(self.imageView.center.x, self.circle2.frame.origin.y - 50);
self.circle3.bounds = CGRectMake(0, 0, 10, 10);
[self addSubview:self.circle3];
}
return self;
}
// 向上轻扫事件
- (void)didSwipeGes {
// 移除圆点
[self.circle1 removeFromSuperview];
[self.circle2 removeFromSuperview];
[self.circle3 removeFromSuperview];
// 旋转并缩小,直至消失
[UIView animateWithDuration:1.5 animations:^{
self.imageView.frame = CGRectMake(SCREEN_WIDTH/2, 0, 0, 0);
self.imageView.transform = CGA
4000
ffineTransformMakeRotation(179);
self.imageView.transform = CGAffineTransformMakeRotation(358);
} completion:^(BOOL finished) {
[self removeSelf];
}];
}
// 移除发送视图
- (void)removeSelf {
[self removeFromSuperview];
}
@end
使用:
// ViewController.m
#import "ViewController.h"
#import "HTSendAnimation.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
HTSendAnimation *sendView = [[HTSendAnimation alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
sendView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
[self.view addSubview:sendView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- iOS控件的动画显示与隐藏
- iOS使用xib文件创建一个组件为子控件,进行复用
- ios UIView控件设置动画后添加点击事件不起作用
- 二 :ios学习笔记 控件、全屏及动画
- IOS UI学习教程之使用UIImageView控件制作动画
- iOS可复用控件之滚动按钮组
- 论坛源码推荐:适用于iOS 7的图片和视频管理控件 Flipboard开源高性能动画GIF引擎
- iOS可复用控件之修改SDCycleScrollView实现轮播图的缩放效果
- IOS开发-UI学习-使用UIImageView控件制作动画
- iOS使用xib文件创建一个组件为子控件,进行复用
- ios控件加载图片,plist,懒加载,序列帧动画,添加动画效果。
- iOS可复用控件之折线图
- iOS可复用控件之调节控件
- iOS基础控件-UIImageView,图片视图,配合点击手势,点击一个图片,开始动画
- iOS工作记录7 :ios控件加载图片,plist,懒加载,序列帧动画,添加动画效果(实用例子)
- iOS几个功能:1.摇一摇;2.震动;3.简单的摇动动画;4.生成二维码图片;5.发送短信;6.播放网络音频等
- iOS为你的数字添加动画:AMAnimatedNumber控件
- IOS控件 动画操作 与 CALayer 简单操作
- iOS控件——UIView与UIImageView播放动画的实现方法
- ios给控件添加动画效果