【问题标题】:How to increase picker view ( transformed pickerview ) width?如何增加选择器视图(转换后的选择器视图)宽度?
【发布时间】:2009-12-19 08:35:48
【问题描述】:

我正在尝试水平滚动选择器视图,这是我的代码。

在 viewDidLoad 中我是这样做的,

     CGRect frame = horizontalPickerView.frame;
            frame.size.width = 50;
            frame.size.height = 216;
            frame.origin.x=90;
            frame.origin.y = 200;
            horizontalPickerView.frame = frame;

            horizontalPickerView.transform = CGAffineTransformMakeRotation(3.14159/2); 






- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
        UILabel *lbl = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, 20)] autorelease];
        lbl.transform = CGAffineTransformMakeRotation(-3.14159/2);
        lbl.text = @"hi";
        return lbl;
    }

但问题是我无法将选择器视图的宽度更改为超过 216.0,如果我尝试这样做,则会留下黑色背景。

CorrectImage http://img709.imageshack.us/img709/6982/picture5g.png这是正确的图片

现在如果我这样做

CGRect frame = horizontalPickerView.frame;
                frame.size.width = 50;
                frame.size.height = 300;
                frame.origin.x=120;
                frame.origin.y = 200;
                horizontalPickerView.frame = frame;

                horizontalPickerView.transform = CGAffineTransformMakeRotation(3.14159/2);

我知道了image http://img46.imageshack.us/img46/2792/picture6b.png

我见过像 Seelibrity 这样的应用程序,其中的选择器具有适合屏幕的宽度。 请帮我解决这个问题?

【问题讨论】:

    标签: iphone cocoa-touch xcode iphone-sdk-3.0


    【解决方案1】:

    UIPickerView 对高度的变化非常敏感,因此直接更改其框架或对 UIPickerView 应用变换会导致呈现伪影。我所知道的调整 UIPickerView 大小的唯一可靠方法是将其放置在透明的 UIView 中,然后对该持有者视图应用缩放(和旋转,在您的情况下)变换。

    我在this answer 中提供了一个示例。

    【讨论】:

    • 或者他可以使用 UIScrollView。
    • UITableView 会是更好的选择,因为数据源和单元格显示方法已经存在。 UIScrollView 需要他重新发明轮子来完成 UIPickerView 所做的很多事情。即使使用 UITableView 也需要大量自定义图稿和覆盖的子视图,以及一些管理当前选定行的机制。
    【解决方案2】:

    尝试以下方法:

    使用“open as”->“Pain text file”选项打开您的xib文件

    搜索选择器视图对象:

    <object class="IBUIPickerView" id="648806599">
    <reference key="NSNextResponder" ref="191373211"/>
    <int key="NSvFlags">292</int>
    <string key="NSFrame">{{0, 83}, {100, 50}}</string>  ---> here
    <reference key="NSSuperview" ref="191373211"/>
    <bool key="IBUIOpaque">NO</bool>
    <bool key="IBUIClipsSubviews">YES</bool>
    <bool key="IBUIMultipleTouchEnabled">YES</bool>
    <bool key="IBUIShowsSelectionIndicator">YES</bool>
    </object>
    

    更改 NSframe,也许这会有所帮助。

    问候

    亚历杭德拉!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      相关资源
      最近更新 更多