我的控制器中有一个带有2个UIViews的笔尖和2个带有IBOutlet的UILabel。
我正在增加和减少这些UIViews的高度看起来像一个条形,以指示什么时候是100%或更少 - 就像一个条形图差不多。
我对两个条形图(重复使用)使用以下方法,但是第一个UIView(条形)位置正确但第二个条形图太低 - Y轴错误。然而,两者的高度都是正确的。
有人有什么想法吗?我已经将它们定位在界面构建器中,我实际上在这个方法中所做的就是改变高度(基本上)
//Position the point, size and label of a rating bar
- (void)configureRatingBar:(UIView *)vRatingBar
andRatingLabel:(UILabel *)lRatingLabel
usingRating:(NSDecimalNumber *)rating
{
//NSDecimalNumber *foodRating = [self calculateRating:self.currentHotel.foodAndBeverageRating];
NSString *formattedRating = [self formatRating:rating];
lRatingLabel.text = formattedRating;
float newHeight = [rating floatValue]; //The height will be based on the rating 100 max
CGRect currentFrame = vRatingBar.frame; //Current frame of the rating view
//CGPoint currentPoint =
// [vRatingBar convertPoint:vRatingBar.frame.origin toView:vReviews];
CGPoint currentPoint = vRatingBar.frame.origin; //Current point of the rating view
float newYaxis = currentPoint.x + (100 - newHeight); //Y axis must move down with the decreasing rating from 0 (100 %) down
[vRatingBar setFrame:CGRectMake(currentPoint.x, newYaxis, currentFrame.size.width, newHeight)];
[lRatingLabel setFrame:CGRectMake(currentFrame.size.width / 34, newHeight - 20, 34, 21)];
}
答案 0 :(得分:0)
我看到你有这条线:
float newYaxis = currentPoint.x + (100 - newHeight); //Y axis must move down with the decreasing rating from 0 (100 %) down
使用currentPoint.x进行计算的位置。这应该是currentPoint.y吗?