【问题标题】:Star-Half image is not displaying in Custom RatingView IOS自定义 RatingView IOS 中未显示 Star-Half 图像
【发布时间】:2015-01-20 11:36:42
【问题描述】:

我正在使用本教程 http://www.raywenderlich.com/1768/uiview-tutorial-for-ios-how-to-make-a-custom-uiview-in-ios-5-a-5-star-rating-view 自定义评分栏。但我不能给半分。当用户触摸 imageview 时,我试图显示半星。请给我建议

【问题讨论】:

标签: ios


【解决方案1】:

终于解决了半星问题。

if (!self.editable) return;

//The rating starts out as 0 and then builds from there.
CGFloat newRating = 0;
//loop through the image collection backwards so if it exits the loop it will have identified the MAX
for(int i = self.imageViews.count - 1; i >= 0; i--) {
    UIImageView *imageView = [self.imageViews objectAtIndex:i];

    CGFloat distance = touchLocation.x - imageView.frame.origin.x;

    CGFloat frameWidth = imageView.frame.size.width;

    if (distance <= 0){
        //this means that the click was to the left of the frame
       continue;
    }
    if (distance /frameWidth >.75) {
        //If this ratio is >.75 then you are to the right 3/4 of the image or past th image
        newRating = i + 1;
        break;
    } else {
        //you didn't drop out or mark the entire star, so mark it half.
        newRating = i + 0.5;
        break;
    }
}

self.rating = newRating;

【讨论】:

    猜你喜欢
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    相关资源
    最近更新 更多