iOS可复用控件之发送动画
来源:互联网 发布:惠州网络问政 编辑:程序博客网 时间:2024/05/16 17:50
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 = CGAffineTransformMakeRotation(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
阅读全文
0 0
- iOS可复用控件之发送动画
- iOS可复用控件之调节控件
- ios 控件的动画隐藏
- IOS 控件带动画移动
- iOS 动画之CALayer动画
- iOS可复用控件之表盘
- IOS之动画效果
- IOS之动画
- IOS之制作动画
- IOS之动画
- IOS之常用动画
- IOS之动画
- IOS 之 动画 知识
- IOS之动画
- IOS之动画
- iOS之Transition动画
- iOS 之连续动画
- IOS之动画
- lnmp的数据库缓存---->memcache
- Latex-特殊公式
- P1074 靶形数独
- Android 性能测试之方向与框架篇
- $(#id).val()在控制台可以获取到id的值,在js中却报错
- iOS可复用控件之发送动画
- Pareto最优解排序
- session监听器
- Linux 防火墙
- samba和squid扩展
- pip安装模块
- APP中的 H5和原生页面如何分辨、何时使用
- aop xml 配置方式解析过程
- Android 突破64K方法数的限制