iOS 模仿微信红包动画

热门标签

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

//
//  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

 

标签:

未经允许不得转载:作者:SheaYang, 转载或复制请以 超链接形式 并注明出处 技术狗|博客
原文地址:《iOS 模仿微信红包动画》 发布于2019-12-04

分享到:
赞(0)

评论 抢沙发

3 + 3 =


iOS 模仿微信红包动画

长按图片转发给朋友

Vieu4.0主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录