iOS -- 雷达加水波纹效果

项目中有使用,直接标记一下,没有怎么整理代码

先看效果图

  

一:雷达效果(这个很简单,使用的三方库,VIGRadarView,可以直接搜到)

使用:


#import "VIGRadarView.h"

@property (nonatomic, strong) VIGRadarView *radarView;

-(VIGRadarView *)radarView {
    if (!_radarView) {
        _radarView = [[VIGRadarView alloc] initWithFrame:self.view.bounds];
        _radarView.scanSpeed = 0.5;
        [self.view addSubview:_radarView];
    }
    return _radarView;
}
//VIGRadarView.m中 scanPartCircle.png 为雷达线,scanCircle.png 为线圈 可自行更改


- (void)viewDidLoad {
    [super viewDidLoad];

//开始
 [self.radarView start];

//离开时关闭
//  [self.radarView stop];

}

二,水波纹


 //中间动画
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.frame = CGRectMake(self.view.center.x-95, self.view.center.y-95, 190, 190);
    
    shapeLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 190, 190)].CGPath;
    //shapeLayer.fillColor = [UIColor colorWithRed:255/255.0 green:158/255.0 blue:27/255.0 alpha:1.0].CGColor;//黄色
 shapeLayer.fillColor = [UIColor colorWithRed:198/255.0 green:201/255.0 blue:220/255.0 alpha:1.0].CGColor;//蓝色
    shapeLayer.opacity = 0.0;
    
    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    animationGroup.animations = @[[self alphaAnimation],[self scaleAnimation]];
    animationGroup.duration = 3.2;
    animationGroup.autoreverses = NO;
    animationGroup.repeatCount = HUGE;
    [shapeLayer addAnimation:animationGroup forKey:@"animationGroup"];
    
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.frame = CGRectMake(0, 0, 190, 190);
    replicatorLayer.instanceDelay = 0.8;
    replicatorLayer.instanceCount = 4;
    [replicatorLayer addSublayer:shapeLayer];
    
    [self.view.layer addSublayer:replicatorLayer];



- (CABasicAnimation *)alphaAnimation{
    CABasicAnimation *alpha = [CABasicAnimation animationWithKeyPath:@"opacity"];
    alpha.fromValue = @(1.0);
    alpha.toValue = @(0.0);
    return alpha;
}


- (CABasicAnimation *)scaleAnimation{
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform"];
    scale.fromValue = [NSValue valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity, 0.0, 0.0, 0.0)];
    scale.toValue = [NSValue valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity, 1.5, 1.5, 0.0)];
    return scale;
}

三,随机选5个位置放置搜索到的人


           //从数据元中随机选5个数据

            NSMutableArray *randomArray = [[NSMutableArray alloc] init];
            //取随机5个数据
            while ([randomArray count] < 5) {
                int r = arc4random() % [self.tempArr count];
                [randomArray addObject:[self.tempArr objectAtIndex:r]];
            }
            
            [self createFivePlaceWithArrar:randomArray];

    
             

- (void)createFivePlaceWithArrar:(NSArray *)dataArr
{ 
    @autoreleasepool {
        
    BOOL creat = YES;
    NSInteger count = 0;
    //存放搜索到的人  _img为中间头像
    NSMutableArray *arr = [NSMutableArray arrayWithObject:_img];
    
    while (creat) {
        FH_UserInfoModel *model = dataArr[count];
        //放置搜索到的人
        FH_RadioButton *personBtn = [[FH_RadioButton alloc] init];
        CGFloat x = arc4random_uniform(Main_Screen_Width);
        CGFloat y = arc4random_uniform(Main_Screen_Height);
        personBtn.frame = CGRectMake(x, y, 70, 100);
/*
//数据赋值(可忽略)
        personBtn.photoImg.backgroundColor = [UIColor cyanColor];
        personBtn.name.text = [NSString stringWithFormat:@"%@",model.nickName];
        
        if([model.relatoin isEqualToString:@"red"]){
          
            personBtn.stateImg.backgroundColor = [UIColor redColor];
        }else if ([model.relatoin isEqualToString:@"yellow"]){
            
            personBtn.stateImg.backgroundColor = [UIColor yellowColor];
        }else{
           
            personBtn.stateImg.backgroundColor = [UIColor greenColor];
        }
        
        personBtn.tag = count+1009;
        [personBtn addTarget:self action:@selector(cleckPerson:) forControlEvents:UIControlEventTouchUpInside];

*/
        BOOL isMutul = NO;
        
        for (int i=0; i<arr.count; i++) {
            UIView *viewBtn = arr[i];
            //超出这个区域 跳出
            if(CGRectIntersectsRect(personBtn.frame, viewBtn.frame) || x<0 || x>=Main_Screen_Width-70 || y<=64 || y>= Main_Screen_Height-100){
                
                isMutul = YES;
                break;
            }
        }
        
        if(!isMutul && creat ){
           
            [arr addObject:personBtn];
            [self.view addSubview:personBtn];
            count++;
        }
        
        //最多展示5个数据
        if(count == 5) creat = NO;
/*
没有处理数据源,只是从数据源中找出5个
        if(_dataArr.count ==0 ) creat = NO;
        
        if(_dataArr.count <5 && _dataArr.count >0){
            
            if(count == _dataArr.count) creat = NO;
            
        }else{
            if(count == 5) creat = NO;
            
        }
*/

    }
 }
   
}

四:刷新旋转

//换一批按钮
- (void)changeFriendClick:(UIButton *)sender
{
   //旋转
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue = [NSNumber numberWithFloat: M_PI *2];
    animation.duration = 1;
    animation.autoreverses = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = 1; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多 少次
    [self.refreshImg.layer addAnimation:animation forKey:@"updateBtnRotation"];
    


    if(self.tempArr.count >0){
        
      //清除上次所寻找的人
        for (UIView *subView in self.view.subviews) {
            
            if([subView isKindOfClass:[FH_RadioButton class]]){
                
                [subView removeFromSuperview];
            }
        }
        //人数大于5 继续随机展示
        if(self.tempArr.count>5){
            
            NSMutableArray *randomArray = [[NSMutableArray alloc] init];
            while ([randomArray count] < 5) {
                int r = arc4random() % [self.tempArr count];
                [randomArray addObject:[self.tempArr objectAtIndex:r]];
            }
            
            [self createFivePlaceWithArrar:randomArray];
            [self.tempArr removeObjectsInArray:randomArray];//数据不重复
            
        }else{//人数少于5 就全部显示
            
            [self createFivePlaceWithArrar:self.tempArr];
        }
        
    }else{
        
      
    } 
}

五,弹出视图(三方库:YBPopupMenu,可以直接搜到)


#import "YBPopupMenu.h"

//遵循代理 <YBPopupMenuDelegate>

@property (nonatomic, strong) YBPopupMenu* rightPopMenu;//右侧更多下拉框


//右侧按钮点击事件
- (void)rightItemClick:(UIButton *)click
{
    NSArray* items = @[@"查看全部",@"只看红灯好友",@"只看黄灯好友",@"只看绿灯好友"];
    self.rightPopMenu = [YBPopupMenu showRelyOnView:click titles:items icons:nil menuWidth:125 otherSettings:^(YBPopupMenu *popupMenu) {
        popupMenu.isShowShadow = NO;
        popupMenu.showMaskView = NO;
        popupMenu.backColor = [[UIColor blackColor] colorWithAlphaComponent:0.85];
        popupMenu.textColor = [UIColor whiteColor];
        popupMenu.maxVisibleCount = 7;
        popupMenu.itemHeight = 36;
        popupMenu.lineSpace = 12;
    }];
    self.rightPopMenu.delegate = self;
    
}

#pragma mark YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu
{

  NSLog(@"index:L%lu",index);
//处理数据
}

猜你喜欢

转载自my.oschina.net/huangyn/blog/1811313