App直播源码程序开发iOS端签到领奖功能的实现流程

经常看直播的都知道,现在大部分的直播APP都有签到领奖励的功能,从而吸引大量的用户登录和注册APP,增加用户黏性。对于各种签到奖励功能来说,APP直播源码在实现流程方面都是大致一样的。接下来跟大家分享一下,如何实现ios端的签到领奖功能。
1、通过请求服务端获取用户今日有没有领取登录奖励

//请求接口获取今天登录奖励的领取情况
[YBToolClass postNetworkWithUrl:@"User.Bonus" andParameter:nil success:^(int code, id  _Nonnull info, NSString * _Nonnull msg) {
    if (code == 0) {
        NSArray *infos = info;
        bonus_switch = [NSString stringWithFormat:@"%@",[[infos lastObject] valueForKey:@"bonus_switch"]];
        bonus_day = [[infos lastObject] valueForKey:@"bonus_day"];
        bonus_list = [[infos lastObject] valueForKey:@"bonus_list"];
        //自己测试使用的天数
        //bonus_day = testDay;
        int day = [bonus_day intValue];
        dayCount = minstr([[infos lastObject] valueForKey:@"count_day"]);
        if ([bonus_switch isEqual:@"1"] && day > 0 ) {
        //未领取,弹出领取界面
        [self firstLog];
        }
    }
} fail:^{

}];

2、领取的界面都是大同小异,用简单的UICollectionView来展示

//创建UICollectionViewFlowLayout
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
_firstCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(fcX, fcY, fcW, fcH) collectionViewLayout:layout];
_firstCollection.dataSource = self;
_firstCollection.delegate = self;
//注册展示的两个cell
UINib *nib = [UINib nibWithNibName:@"LogFirstCell" bundle:nil];
[_firstCollection registerNib:nib forCellWithReuseIdentifier:IDENTIFIER];
UINib *nib2 = [UINib nibWithNibName:@"LogFirstCell2" bundle:nil];
[_firstCollection registerNib:nib2 forCellWithReuseIdentifier:IDENTIFIER2];
//注册UICollectionView的头尾视图
[_firstCollection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
[_firstCollection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
_firstCollection.backgroundColor = [UIColor whiteColor];
[whiteView addSubview:_firstCollection];
//添加个简单的现实动画
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.8 animations:^{
            whiteView.frame = CGRectMake(_window_width*0.05, _window_height*0.2, _window_width*0.9, height);
        }];
    });
});

3、点击领取按钮,请求接口,服务端改变领取状态并给用户添加奖励,接口请求成功,展示领取登录奖励成功的动画。

UIImageView *lightImageView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.25, _window_height/2-_window_width*0.125-50, _window_width*0.5, _window_width*0.5)];
lightImageView.image = [UIImage imageNamed:@"logFirst_背景"];
[self addSubview:lightImageView];

//旋转动画
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
rotationAnimation.duration = 2;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 9999;
[lightImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

//放大效果,并回到原位
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//速度控制函数,控制动画运行的节奏
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.duration = 0.5;       //执行时间
animation.repeatCount = 1;      //执行次数
animation.autoreverses = NO;    //完成动画后会回到执行动画之前的状态
animation.fromValue = [NSNumber numberWithFloat:0.2];   //初始伸缩倍数
animation.toValue = [NSNumber numberWithFloat:1.2];     //结束伸缩倍数
UIImageView *headerImgView = [[UIImageView alloc]initWithFrame:CGRectMake(lightImageView.left, lightImageView.top-lightImageView.width/3, lightImageView.width, lightImageView.width/3)];
headerImgView.image = [UIImage imageNamed:@"logFirst_成功"];
[self addSubview:headerImgView];
UIImageView *coinImageView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.375, lightImageView.width*0.25+lightImageView.top, _window_width*0.25, _window_width*0.25)];
coinImageView.image = [UIImage imageNamed:@"logFirst_钻石"];
[self addSubview:coinImageView];

[headerImgView.layer addAnimation:animation forKey:nil];
[coinImageView.layer addAnimation:animation forKey:nil];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, coinImageView.bottom+5, _window_width, 22)];
label.textColor = normalColors;
label.font = [UIFont boldSystemFontOfSize:20];
label.textAlignment = NSTextAlignmentCenter;
NSDictionary *subdic = _arrays[[logDay intValue]-1];
label.text = [NSString stringWithFormat:@"+ %@",minstr([subdic valueForKey:@"coin"])];
[self addSubview:label];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [label.layer addAnimation:animation forKey:nil];

});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:0.5 animations:^{
    self.transform = CGAffineTransformMakeScale(0.01, 0.01);
} completion:^(BOOL finished) {
if ([_delegate respondsToSelector:@selector(removeView:)]) {
    //结束后销毁页面
    [_delegate removeView:nil];
}
}];

});

最后添加的是一个简单的旋转和放大缩小的动画。
由此可见,APP直播源码在ios端实现签到奖励功能上起到了重要作用。而这一功能的设立,不仅为用户的使用体验增添了乐趣,还极大程度的增加了用户黏性,促进直播平台的发展。
本文声明原创,转载请注明出处。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值