- (IBAction) showCatPicker {
if (self.catList !=nil) {
self.catList=nil;
[catList release];
}
self.catList = [[NSMutableArray alloc] init];
self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
if(self.catPicker == nil) {
self.catPicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
self.catPicker.showsSelectionIndicator = YES;
self.catPicker.dataSource = self;
self.catPicker.opaque = YES;
self.catPicker.multipleTouchEnabled = YES;
self.catPicker.userInteractionEnabled = YES;
self.catPicker.delegate = self;
}
[self.actionSheet addSubview:self.catPicker];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Select"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor colorWithRed:19.0/255 green:122.0/255 blue:53.0/255 alpha:1.0];
[closeButton addTarget:self action:@selector(dismissGenderPicker:) forControlEvents:UIControlEventValueChanged];
UISegmentedControl *cancelButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Cancel"]];
cancelButton.momentary = YES;
cancelButton.frame = CGRectMake(10, 7.0f, 50.0f, 30.0f);
cancelButton.segmentedControlStyle = UISegmentedControlStyleBar;
cancelButton.tintColor = [UIColor colorWithRed:19.0/255 green:122.0/255 blue:53.0/255 alpha:1.0];
[cancelButton addTarget:self action:@selector(cancelActionSheet) forControlEvents:UIControlEventValueChanged];
[self.actionSheet addSubview:cancelButton];
[self.actionSheet addSubview:closeButton];
[cancelButton release];
[closeButton release];
[self.actionSheet showInView:self.view];
[self.actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
[catPicker reloadComponent:0];
}
8
A
回答
1
self.view.userInteractionEnabled = NO;
self.blurView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.blurView setBackgroundColor:[UIColor lightGrayColor]];
[self.blurView setAlpha:0.3];
[[[UIApplication sharedApplication] delegate].window addSubview:self.blurView];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame];
pickerView.datePickerMode = UIDatePickerModeDate;
[pickerView setBackgroundColor:[UIColor whiteColor]];
[pickerView addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
__block CGRect frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, 220);
self.viewForPicker = [[UIView alloc] initWithFrame:frame];
[self.viewForPicker setBackgroundColor:[UIColor whiteColor]];
[self.viewForPicker addSubview:pickerView];
[[[[UIApplication sharedApplication] delegate] window] addSubview:self.viewForPicker];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
[button setTitle:@"Done" forState:UIControlStateNormal];
[button addTarget:self action:@selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(250, 15, 60, 30)];
[button.layer setCornerRadius:5.0];
[button.layer setBorderWidth:1.0];
[button.layer setBorderColor:[[IMAppStyle appColor] CGColor]];
[self.viewForPicker addSubview:button];
[self.viewForPicker.layer setCornerRadius:8.0];
float animationDuration = 0.25;
[UIView animateWithDuration:animationDuration animations:^{
frame.origin.y -= (180+40+35);
[self.viewForPicker setFrame:frame];
}];
3
你絕對不應該使用UIActionSheet舉行一次的UIDatePicker,因爲此功能已經過時!
子類注
UIActionSheet的目的不是要被繼承,也不應該添加 意見,它的層次結構。如果您需要提供比UIActionSheet API提供的更多 定製的表單,您可以創建自己的 ,並以 的形式呈現presentViewController:animated:completion :.
和
重要:UIActionSheet在iOS的8棄用(請注意, UIActionSheetDelegate也已經過時。)創建和iOS 8的管理行動 張後來,改用UIAlertController用 UIAlertControllerStyleActionSheet的preferredStyle。
你可以很容易地做的是創建一個UIView來保存UIDatePicker並根據需要爲視圖設置動畫。如果需要,你甚至可以添加一個UIToolbar。
下面是一個例子:
創建兩個屬性:
@property (strong, nonatomic) UIDatePicker *theDatePicker;
@property (strong, nonatomic) UIView *pickerView;
創建你的選擇器,將其嵌入到UIView
和顯示:
-(void) createDatePickerAndShow {
UIToolbar *controlToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, pickerView.bounds.size.width, 44)];
[controlToolbar sizeToFit];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Set" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDateSet)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelDateSet)];
[controlToolbar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil] animated:NO];
[theDatePicker setFrame:CGRectMake(0, controlToolbar.frame.size.height - 15, theDatePicker.frame.size.width, theDatePicker.frame.size.height)];
if (!pickerView) {
pickerView = [[UIView alloc] initWithFrame:theDatePicker.frame];
} else {
[pickerView setHidden:NO];
}
CGFloat pickerViewYpositionHidden = self.view.frame.size.height + pickerView.frame.size.height;
CGFloat pickerViewYposition = self.view.frame.size.height - pickerView.frame.size.height;
[pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
pickerViewYpositionHidden,
pickerView.frame.size.width,
pickerView.frame.size.height)];
[pickerView setBackgroundColor:[UIColor whiteColor]];
[pickerView addSubview:controlToolbar];
[pickerView addSubview:theDatePicker];
[theDatePicker setHidden:NO];
[self.view addSubview:pickerView];
[UIView animateWithDuration:0.5f
animations:^{
[pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
pickerViewYposition,
pickerView.frame.size.width,
pickerView.frame.size.height)];
}
completion:nil];
}
And to dismiss the DatePicker:
-(void) cancelDateSet {
CGFloat pickerViewYpositionHidden = self.view.frame.size.height + pickerView.frame.size.height;
[UIView animateWithDuration:0.5f
animations:^{
[pickerView setFrame:CGRectMake(pickerView.frame.origin.x,
pickerViewYpositionHidden,
pickerView.frame.size.width,
pickerView.frame.size.height)];
}
completion:nil];
}
相關問題
- 1. 如何在yii表單中添加日期選擇器?
- 2. 在fragmnet中添加日期選擇器
- 3. jqgrid +添加表單+日期選擇器
- 4. 如何在LiveCode中添加日期選擇器(日曆)?
- 5. 如何增加從日期選擇器中選擇的日期?
- 6. 如何將日期選擇器添加到下拉列表中
- 7. 如何使用jquery日期選擇器手動添加日期
- 8. jQuery的日期選擇器操作
- 9. 如何添加時間選擇與日期選擇器
- 10. 在日期選擇器中添加日期的問題
- 11. 如何在Swift中將日期選擇器添加到UIAlertController(UIAlertView)?
- 12. 如何添加日期選擇器在asp.net mvc 3中?
- 13. 如何在jqgrid中添加日期選擇器
- 14. 如何在日期選擇器中添加javascript的ASP.Net MVC 4
- 15. 如何在日期選擇器中禁用日期時選擇其他日期選擇器中的日期
- 16. 在日期選擇器中添加選擇前一日期的限制
- 17. 在BIRT中添加日期選擇器作爲參數
- 18. 添加第二個日期選擇器,
- 19. 添加天日期選擇器JS
- 20. Jquery |添加活動日期選擇器
- 21. 添加天日期選擇器
- 22. 在jQuery日期選擇器中選擇日期和高亮日期選擇器
- 23. Jquery:在IE和FF上添加日期的日期選擇器
- 24. 如何將日期選擇器添加到Magento中的列?
- 25. 如何爲apex5.0中的字段添加日期選擇器
- 26. 如何添加Yii2瑞在日期選擇器GridView的
- 27. 如何在MVC添加日期選擇器沒有的jQuery
- 28. 如何在wijmo日期選擇器上選擇當前日期
- 29. 如何在選擇日期後隱藏日期選擇器
- 30. 如何增加日期選擇器
絕對正確的,我同意你的看法,因爲iOS的8現在禁止將子視圖添加到UIActionSheet並顯示不能從您的應用中解散的模態空視圖,除非您殺死它! – cdescours
所以這個工作?可能在某處做錯了什麼,但我沒有在屏幕上得到任何東西。 – Moelbeck