2010-10-14 64 views
1

我遇到了一個UIPickerView一個奇怪的行爲旋轉:UIPickerView與日期只在一個方向

我試圖表現出動作片內的日期選擇器。 一切運轉良好,除了車輪首先在一個方向旋轉!

如果您開始向上旋轉並將方向改爲向下 - 它會起作用。但是當您嘗試開始旋轉時,選取器不會移動。

這裏是我的代碼:

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker" 
                delegate:self 
             cancelButtonTitle:@"Abbrechen" 
            destructiveButtonTitle:nil 
             otherButtonTitles:@"Auswählen",nil];  
    // Add the picker 
    UIDatePicker *tmpPickerView = [[UIDatePicker alloc] init]; 
    tmpPickerView.datePickerMode = UIDatePickerModeDate; 

    [tmpPickerView addTarget:self 
    action:@selector(pickerChanged:) 
    forControlEvents:UIControlEventValueChanged]; 

    [menu addSubview:tmpPickerView];    
    [menu showInView:self];   

    CGRect menuRect = menu.frame; 
    menuRect.origin.y -= 214; 
    menuRect.size.height = 300; 
    menu.frame = menuRect; 

    CGRect pickerRect = pickerView.frame; 
    pickerRect.origin.y = 174; 
    pickerView.frame = pickerRect; 

    [tmpPickerView release];  
    [menu release]; 

回答

0

的問題是,UIDatePicker被延伸超出UIActionSheet的界限,你可以看到,如果你設置

menu.clipsToBounds = YES;

爲了適當調整大小,將您的框架大小調整代碼更改爲

CGRect pickerRect = tmpPickerView.frame; 
CGRect menuRect = menu.frame; 

pickerRect.origin.y = menuRect.size.height; 
menuRect.size.height = menuRect.size.height + pickerRect.size.height; 
menuRect.origin.y = menuRect.origin.y - pickerRect.size.height; 

menu.frame = menuRect;  
tmpPickerView.frame = pickerRect; 
相關問題