2012-10-27 36 views
0

這是我用來顯示UIPickerView的方法,當按下按鈕時,我會用什麼方法解僱它?任何人有一個想法如何解僱這個DatePicker /子視圖

if (buttonIndex == 4) { 
    int height = 255; 

//創建新的視圖

UIView * newView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, 320, height)]; 
    newView.backgroundColor = [UIColor colorWithWhite:1 alpha:1]; 

//添加工具欄

UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 40)]; 
    toolbar.barStyle = UIBarStyleBlack; 

//添加按鈕

UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:nil action:@selector(dismissCustom:)]; 
    toolbar.items = [NSArray arrayWithObjects:infoButtonItem, nil]; 

//添加日期選取器

UIDatePicker *datePicker = [[UIDatePicker alloc] init]; 
    datePicker.datePickerMode = UIDatePickerModeDateAndTime ; 
    datePicker.hidden = NO; 
    datePicker.date = [NSDate date]; 
    datePicker.frame = CGRectMake(0, 40, 320, 250); 
    [datePicker addTarget:self action:nil/*@selector(changeDateInLabel:)*/ forControlEvents:UIControlEventValueChanged]; 
    [newView addSubview:datePicker]; 

//添加彈出視圖

[newView addSubview:toolbar]; 
[self.view addSubview:newView]; 

//它的動畫在屏幕上

CGRect temp = newView.frame; 
    temp.origin.y = CGRectGetMaxY(self.view.bounds); 
    newView.frame = temp; 
    [UIView beginAnimations:nil context:nil]; 
    temp.origin.y -= height; 
    newView.frame = temp; 
    [UIView commitAnimations]; 

} 

回答

0

要刪除的觀點,另做動畫。只需反轉框架設置,使其離開屏幕即可。動畫完成後,通過調用[newView removeFromSuperview]來刪除'newView'。

你應該考慮使用UIView動畫的新塊形式。這將使它更容易。

另一件事。如果你有一個自定義視圖類,爲什麼這個自定義類沒有做所有的工作來設置自己?

此外,它是類名稱以大寫字母開頭的標準慣例。這使得在查看代碼時很容易從變量名稱中指定類名。

+0

謝謝你,我會給你一個去!只是一個問題,什麼是新的塊形式?我會記住最後一點。 –

+0

哦,我也沒有將自定義視圖類設置爲全部,因爲我只是在測試一些東西。我不小心把錯誤的代碼放進去了。 –

+0

看看UIView的參考文檔。查看**下的方塊列表** – rmaddy

相關問題