1

我以编程方式将两个自定义 UIPickerViews 添加到另一个视图(MainView)。它们工作得很好,但在 MainView 的任何部分发生触摸事件之前它们是不可见的。我已经检查了 UIPickerView 和 UIView 的类引用,但没有找到任何可以“刷新”视图的东西,除非我遗漏了一些明显的东西?

这是我在 MainView.m 中的 drawRect 方法。我尝试在 viewDidLoad 中做同样的事情,但没有成功。自定义旋转/变换等是否与它有关?

- (void)drawRect:(CGRect)rect { 
    CGRect pickerFrame = CGRectMake(50, -32, 30, 180);
    m_picker1 = [[UIPickerView alloc] initWithFrame:pickerFrame];
    m_picker1.delegate = self;  
    m_picker1.tag = k_ptag1;
    m_picker1.showsSelectionIndicator =YES;  
    m_picker1.backgroundColor = [UIColor clearColor]; 
    CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);  
    rotate = CGAffineTransformScale(rotate, 0.075, 0.85);  
    [m_picker1 setTransform:rotate];  
    [self addSubview:m_picker1]; 

    pickerFrame = CGRectMake(50, 67, 30, 180);
    m_picker2 = [[UIPickerView alloc] initWithFrame:pickerFrame];
    m_picker2.delegate = self;  
    m_picker2.tag = k_ptag2;
    m_picker2.showsSelectionIndicator =YES;  
    m_picker2.backgroundColor = [UIColor clearColor]; 
    rotate = CGAffineTransformMakeRotation(3.14/2);  
    rotate = CGAffineTransformScale(rotate, 0.075, 0.85);  
    [m_picker2 setTransform:rotate];  
    [self addSubview:m_picker2];
}
4

1 回答 1

2

您在视图的控制器中添加子视图,而不是视图本身。我建议您熟悉 MVC 设计模式。

drawRect 应该只用于视图本身的实际绘制,而不是子视图。

于 2009-05-28T13:02:00.320 回答