//
// RedPacketVC.m
// 红包
//
// Created by Sen wang on 2017/8/15.
// Copyright © 2017年 王森. All rights reserved.
//
#import "RedPacketVC.h"
#import "UIView+Extension.h"
#define kMain_Width [UIScreen mainScreen].bounds.size.width
#define kMain_Height [UIScreen mainScreen].bounds.size.height
#define kiPhone4s ((kMain_Height == 480) ? YES : NO)
#define kiPhone5s ((kMain_Height == 568) ? YES : NO)
#define kiPhone6s_7s ((kMain_Height == 667) ? YES : NO)
#define kiPhone6sP_7sP ((kMain_Height == 736) ? YES : NO)
@interface RedPacketVC ()
@property (nonatomic, strong) UIImageView *imageTop;
@property (nonatomic, strong) UIImageView *imageBottom;
@property (nonatomic, strong) UIButton *sendBtn;
@end
@implementation RedPacketVC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self wxRedPacket];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/** * 仿微信红包 */
- (void)wxRedPacket {
//深色背景
self.imageTop = [[UIImageView alloc] init];
self.imageTop.frame = CGRectMake(0, 0, kMain_Width, kMain_Height * 0.4);
self.imageTop.image = [UIImage imageNamed:@"shanghong"];
//发红包按钮
self.sendBtn =
[[UIButton alloc] initWithFrame:CGRectMake((kMain_Width - 100) / 2, self.imageTop.height - 50, 100, 100)];
_sendBtn.layer.masksToBounds = YES;
_sendBtn.layer.cornerRadius = _sendBtn.bounds.size.height / 2;
[_sendBtn setBackgroundImage:[UIImage imageNamed:@"开"] forState:UIControlStateNormal];
[_sendBtn addTarget:self action:@selector(sendBtnAction:) forControlEvents:UIControlEventTouchUpInside];
self.imageBottom = [[UIImageView alloc] init];
CGFloat height1 = 15;
if (kiPhone5s) {
height1 = 1;
}
if (kiPhone6s_7s) {
height1 = 8;
}
if (kiPhone6sP_7sP) {
height1 = 15;
}
self.imageBottom.frame = CGRectMake(0, _sendBtn.y - height1, kMain_Width, kMain_Height * 0.7);
self.imageBottom.image = [UIImage imageNamed:@"xiahong"];
[self.view addSubview:self.imageTop];
[self.view addSubview:self.imageBottom];
[self.view addSubview:_sendBtn];
}
- (void)sendBtnAction:(UIButton *)sendBtn {
CABasicAnimation *transformAnima = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
transformAnima.toValue = [NSNumber numberWithFloat:M_PI];
transformAnima.duration = 0.6;
transformAnima.cumulative = NO;
// 动画结束时是否执行逆动画
transformAnima.autoreverses = YES;
transformAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
sendBtn.layer.zPosition = 5;
sendBtn.layer.zPosition = sendBtn.layer.frame.size.width / 2.f;
transformAnima.repeatCount = MAXFLOAT;
[sendBtn.layer addAnimation:transformAnima forKey:@"rotationAnimationY"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self updataFrame];
});
}
- (void)updataFrame {
CGFloat topDistance = -self.imageTop.height / 2;
[self.sendBtn removeFromSuperview];
self.sendBtn =
[[UIButton alloc] initWithFrame:CGRectMake((kMain_Width - 100) / 2, self.imageTop.height - 50, 100, 100)];
[_sendBtn setBackgroundImage:[UIImage imageNamed:@"开"] forState:UIControlStateNormal];
[self.view addSubview:_sendBtn];
[UIView animateWithDuration:0.4
animations:^{
self.imageTop.y = topDistance;
self.sendBtn.y = -topDistance - 50;
self.imageBottom.y = kMain_Height;
}];
}
@end
iOS 模仿微信红包动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- iOS应用国际化思路:iOS应用的国际化思路是将程序中的标签、提示等信息放在资源文件中,程序需要支持哪些国...
- *****最开始很喜欢苹果的白色弹出框,很是精致,但是在实际软件使用中发现自带弹窗启动有些慢,而且发现微信、支付宝...