• ios 类似淘宝评论星星功能


    创建星星视图:

    //星星

        _myview = [[UIView alloc]initWithFrame:CGRectMake(95, 5, 200, 50)];

        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(huadong:)];

        [_myview addGestureRecognizer:pan];

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dianji:)];

        [_myview addGestureRecognizer:tap];

        [view1 addSubview:_myview];

        for (int i = 0; i < 5; i++) {

            imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star01"]];

            imageView.frame = CGRectMake(_myview.bounds.origin.x+((i+1)*24), _myview.bounds.origin.y, 24, 24);

            

            [_myview addSubview:imageView];

            [_allStar addObject:imageView];

        }

     

    //分别在点击和滑动手势实现方法

     

    #pragma mark - 滑动的坐标

    -(void)huadong:(UIPanGestureRecognizer *)pan{

        CGPoint translation = [pan locationInView:_myview];

        

        for(int i = 0;i < 5 ; i++)

        {

            UIImageView *im ;

            im = _allStar[i];

            //NSLog(@"_all[%i] = (%f,%f)",i,im.frame.origin.x,im.frame.origin.y);

            

            if ((translation.x > 0)&&(translation.x < 144)&&(translation.y > 0)&&(translation.y < 24))

            {

                NSString *myscore = [NSString stringWithFormat:@"%i",((int)translation.x)/24];

                //UILabel *score = [[UILabel alloc]initWithFrame:CGRectMake(150, 180, 100, 100)];

                //[scrollView addSubview:score];

                //score.text = myscore;//_score是一个UILablemyscore为分数,显示在给用户看,关于这个不在赘述

                

                

                star = [myscore intValue];

                

                //星星

                if (im.frame.origin.x > translation.x)

                {

                    im.image =[UIImage imageNamed:@"star01"];

                }

                else

                {

                    im.image =[UIImage imageNamed:@"star02"];

                }

            }

        }

    }

    #pragma mark - 点击的坐标

    -(void)dianji:(UITapGestureRecognizer *)tap{

        CGPoint translation = [tap locationInView:_myview];

        

        for(int i = 0;i < 5 ; i++){

            

            UIImageView *im ;

            im = _allStar[i];

            

            if ((translation.x > 0)&&(translation.x < 144)&&(translation.y > 0)&&(translation.y < 24)) {

                NSString *myscore = [NSString stringWithFormat:@"%i",((int)translation.x)/24];

                

                //星星

                star = [myscore intValue];

     

                if (im.frame.origin.x > translation.x) {

                    im.image =[UIImage imageNamed:@"star01"];

                }else{

                    im.image =[UIImage imageNamed:@"star02"];

                }

            }

        }

    }

  • 相关阅读:
    vue 如何点击按钮返回上一页
    vue遍历数组和对象的方法以及他们之间的区别
    css隐藏滚动条
    DOM编程以及domReady加载的几种方式
    修改默认滚动条默认样式
    面试题集锦
    正则表达式
    闭包及应用以及顺序处理ajax请求
    实现自己的(模仿jquery)toggle函数
    Asp.Net与SEO Viewstate优化终极解决方案
  • 原文地址:https://www.cnblogs.com/damnbird/p/4911061.html
Copyright © 2020-2023  润新知