3

我用自定义单元格制作了一个表格视图,如下所示。

![自定义单元格][1]

![输出表视图][2]

我需要在每个单元格中使用选择器而不是滑块来设置评级

在此处输入图像描述

我只需要在按钮下方设置选择器位置,它会随按钮位置而变化

如何实现它。

iu 尝试使用以下框架和边界,但每次都给出相同的值

   - (IBAction) buttonClicked:(UIButton *)sender
    {      
          NSLog(@"------%f  %f",sender.frame.origin.x , sender.frame.origin.y); //250, 2

         NSLog(@"------%f  %f",sender.bounds.origin.x , bounds.frame.origin.y); // 0.0 , 0.0

       picker.frame = CGRectMake(sender.bounds.origin.x , sender.bounds.origin.y, 50, 216);
}
4

3 回答 3

6

您在最后一行使用“.x”值两次,而不是第二次使用“.y”值有错字。

此外,您需要将坐标转换为显示选择器的视图的坐标。包括显示选择器的代码,我可以帮助您。

它会是这样的:

picker.frame = [viewThatYouAreDisplayingThePickerIn convertRect:sender.frame fromView:sender.superview];
于 2013-01-28T06:46:24.293 回答
1

但是,如果您想获得相对于主视图的按钮框架,请使用此:

 CustomCell *cell = (CustomCell *)[self.table cellForRowAtIndexPath:indexPath];

 CGRect buttonFrame = [cell.superview convertRect:cell.customButton.frame toView:self.view];
于 2013-01-28T06:55:07.900 回答
0

按钮有一个名为locationInView继承自的方法UITouch

Returns the current location of the receiver in the coordinate system of the given view.
- (CGPoint)locationInView:(UIView *)view

苹果开发者参考

于 2013-01-28T06:59:43.533 回答