码迷,mamicode.com
首页 > 移动开发 > 详细

ios 类似淘宝评论星星功能

时间:2015-10-26 15:27:16      阅读:498      评论:0      收藏:0      [点我收藏+]

标签:

创建星星视图:

//星星

    _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"];

            }

        }

    }

}

ios 类似淘宝评论星星功能

标签:

原文地址:http://www.cnblogs.com/damnbird/p/4911061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!