我正在以编程方式将两个自定义UIPickerView添加到另一个视图(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];
}
答案 0 :(得分:2)
您可以在视图的控制器中添加子视图,而不是视图本身。我建议您熟悉MVC设计模式。
drawRect仅用于实际绘制视图本身,而不是用于子视图。