【问题标题】:UIPickerView not appearing until touch occursUIPickerView 直到发生触摸才出现
【发布时间】:2009-05-28 11:24:29
【问题描述】:

我以编程方式将两个自定义 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];
}

【问题讨论】:

    标签: iphone cocoa-touch uiview touch uipickerview


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我已将所有适当的东西移到 UIViewController 中,现在选择器显示正确。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多