美文网首页加载动画
iOS 水波扩散扫描,scrollView动画,UIlabel加

iOS 水波扩散扫描,scrollView动画,UIlabel加

作者: 何康老鬼 | 来源:发表于2021-12-23 10:16 被阅读0次

工作中有一个需求,就是一个水波扩散动画扫描之后,再把collectionView偏移动画一下,具体效果看下图:

RPReplay_Final1640223028.gif

实现

  • 先自定义一个视图继承UIView
  • 在-(void)drawRect:(CGRect)rect方法中实现动画效果
  • 创建N个CALayer 添加不同时间段的动画,在循环创建中,设置动画时间不同
  • 在中间位置添加视图,在上面放入头像做一个缩放动画效果
  • 然后scrollView做一个动画偏移的效果

主要的功能点代码

//创建缩放动画
 CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.fromValue = @1;
    scaleAnimation.toValue = @(3.832);
    scaleAnimation.beginTime = CACurrentMediaTime() + (double)(index * 3) / self.circleIncrement;
    scaleAnimation.duration = 3;
    scaleAnimation.repeatCount = HUGE;// 重复次数设置为无限
//创建CALayer
 CALayer *pulsingLayer = [CALayer layer];
    pulsingLayer.borderWidth = 0.5;
    pulsingLayer.borderColor = [UIColor colorWithDynamicLight:[UIColor colorWithHexString:@"#E1EBF5"] dark:[UIColor colorWithHexString:@"#3C3C3E"]].CGColor;
    pulsingLayer.frame = CGRectMake((rect.size.width - PtOnIPhone6(60))/2, (rect.size.height - PtOnIPhone6(60))/2, PtOnIPhone6(60), PtOnIPhone6(60));
    pulsingLayer.cornerRadius = PtOnIPhone6(30);
    [pulsingLayer addAnimation:animation forKey:@"plulsing"];
//scrollView 偏移动画,这里会存在一个问题,如果内部那个动画设置的时间过长可能会导致回弹时cell消失的效果
  [UIView animateKeyframesWithDuration:1 delay:0 options:UIViewKeyframeAnimationOptionLayoutSubviews|UIViewKeyframeAnimationOptionCalculationModeCubic animations:^{
            [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.9 animations:^{
                [self.cardCollectionVIew setContentOffset:CGPointMake(80, 0) animated:false];
            }];
            [UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.2 animations:^{
                [self.cardCollectionVIew setContentOffset:CGPointMake(0, 0) animated:false];
            }];
        } completion:^(BOOL finished) {
            //Completion Block
        }];
//UIlabel 加载HTML 这里有个问题 后台返回的直接加载的话,默认其他的颜色为黑色,如果你想改变其他的颜色需要在前边加一个标签包裹起来处理,我们后台返回的是格式是:已有<font color='#0A84FF'>986808</font>人参加测评
  NSString *htmlString = weakSelf.viewModel.testIndexModel.tips;
        htmlString = [NSString stringWithFormat:@"<span style='color:#999999'>%@</span>",htmlString];
        NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
        weakSelf.tipLabel.attributedText = attributedString;
//添加随机头像,判断随机的点是否与中间的视图fram交叉,有就重新随机,其中205是随机的安全距离 整个父视图的宽减去随机头像的宽

    NSInteger arcRectX = arc4random()%205;
    NSInteger arcRectY = arc4random()%205;
    
    UIImageView *pointImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, PtOnIPhone6(25),PtOnIPhone6(25))];
    pointImage.layer.cornerRadius = PtOnIPhone6(12.5);
    pointImage.layer.masksToBounds = true;
    
    CGRect rect = CGRectMake(arcRectX, arcRectY, PtOnIPhone6(25), PtOnIPhone6(25));
    CGRect iconRect = CGRectMake(PtOnIPhone6(170)/2, PtOnIPhone6(170)/2, PtOnIPhone6(60), PtOnIPhone6(60));
    if (CGRectIntersectsRect(rect, iconRect)) {
        NSLog(@"重叠了-----%@---%@",NSStringFromCGRect(rect),NSStringFromCGRect(iconRect));
        [self addPointView];
        return;
    }

相关文章

  • iOS 水波扩散扫描,scrollView动画,UIlabel加

    工作中有一个需求,就是一个水波扩散动画扫描之后,再把collectionView偏移动画一下,具体效果看下图: 实...

  • iOS水波扩散效果实现

    实现效果 水波纹从中心从外侧扩散的效果实现: 实现思路 1、通过一个定时器等,重复的创建一个圆;2、将创建的圆,进...

  • iOS 水波动画

    最近遇到了水波波动的动画效果,看书资料学习下,做了个小demo,希望别人有所帮助。这里我是用CAShapeLaye...

  • 使用CADisplayLink实现UILabel动画特效

    使用CADisplayLink实现UILabel动画特效 使用CADisplayLink实现UILabel动画特效

  • iOS动画之水波动画

    前言:现在很多app为了提供好的交互效果给用户,通常都会通过添加动画效果来达到目的。一个好的动画效果往往会起到神来...

  • iOS缩放动画 + 高度从无到有再到无动画

    缩放动画 UILabel *tipLab=[[UILabel alloc]initWithFrame:CGRect...

  • iOS动画-扩散波纹效果

    最终效果 实现思路 动画的表现形式是颜色以及大小的变化,整体效果可以看做多个单独的波纹效果的叠加。因此我们可以创建...

  • iOS水波纹动画

    最近在学习动画,就做了一个简单的水波纹动画。这个效果可以用在部分个人中心页的边界或者进度的显示。 先附上githu...

  • iOS水波动画实现

    效果如下: 实现这个水波动画主要还是要利用下初中的知识:正弦函数 A 表示振幅,也就是使用这个变量来调整波浪的高度...

  • iOS 水波纹动画

    春节后经过数天的努力上架了公司一个项目后,暂时又进入了空闲期,于是就着手整理一下项目中遇到的一些有意思的需求。废话...

网友评论

    本文标题:iOS 水波扩散扫描,scrollView动画,UIlabel加

    本文链接:https://www.haomeiwen.com/subject/ptkhqrtx.html