我是iphone開發新手。我正在製作的應用使用選取器從用戶輸入值。我設法隱藏了選取器,直到用戶點擊按鈕。我在viewdidload中使用了mypicker.alpha = 0;
,所以程序啓動時選擇器不可見。當用戶點擊開始按鈕時,它執行代碼mypicker.alpha=1;
。我想在用戶選擇一個值後關閉選取器。我怎麼做?任何人有任何提示或教程?我看了幾個,但他們混亂!另外我如何讓自動選取器從底部出現? (如鍵盤!)在iphone應用程序中關閉UIpicker
0
A
回答
1
我最近開始使用的一種方法是在選取器後面放置一個陰影按鈕,一個大的透明黑色按鈕,屏幕大小爲黑色,alpha = 0.3([UIColor colorWithWhite:0 alpha :0.3f]我認爲是)。這只是在屏幕的其餘部分上放置一個透明的「陰影」,除了選取器之外,類似於使用UIAlertView時的外觀。然後鉤上按鈕,以便它將resignFirstResponder發送到選取器。現在,當用戶完成拾取時,他們只需點擊陰影區域內選擇器外的任何位置,然後該按鈕就會使拾取器退出,並且拾取器可以向下滑動,並且按鈕會通過動畫淡出。
選擇器滑動上/下動畫可以完成,我在家裏有它的代碼,但現在無法訪問它。您可以使其看起來像鍵盤一樣發送與鍵盤發送相同的通知。
0
不要使用:
mypicker.alpha = 1;
mypicker.alpha = 0;
你應該使用:
mypicker.hidden = YES;
mypicker.hidden = NO;
,以顯示或隱藏選擇器。
爲了使它從底部出現,您可以使用塊動畫。我會用:
.h文件:
@interface viewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
BOOL shouldMoveDown;
IBOutlet UIPickerView * picker;
}
- (IBAction)movePicker;
.m文件:
#pragma mark - View lifecycle
- (void)viewDidLoad; {
[super viewDidLoad];
picker.hidden = YES;
shouldMoveDown = NO;
picker.userInteractionEnabled = NO;
}
- (IBAction)movePicker; {
if(shouldMoveDown){
[UIView animateWithDuration:1.0
animations:^{
CGRect newRect = picker.frame;
newRect.origin.y += 236; // 480 - 244 (Height of Picker) = 236
picker.frame = newRect;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
picker.hidden = YES;
shouldMoveDown = NO;
picker.userInteractionEnabled = NO;
}
completion:^(BOOL finished){
;
}];
}];
}
else{
picker.hidden = NO;
//picker.frame = CGRectMake(picker.frame.origin.x, 480, picker.frame.size.width, picker.frame.size.height);
[UIView animateWithDuration:1.0
animations:^{
CGRect newRect = picker.frame;
newRect.origin.y -= 236; // 480 - 244 (Height of Picker) = 236
picker.frame = newRect;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1.0
animations:^{
shouldMoveDown = YES;
picker.userInteractionEnabled = YES;
}
completion:^(BOOL finished){
;
}];
}];
}
}
#pragma mark -
#pragma mark Picker Delegate Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView; {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component; {
return 1;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; {
return @"1";
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; {
}
很明顯,你可以設置選擇器的任何您想要的方式。您也可以改變發生這種情況的速度!希望這可以幫助!
相關問題
- 1. iPhone應用程序在iPad上關閉
- 2. 關閉iPhone應用程序的問題
- 3. 應用程序掛起時關閉IPhone
- 4. 如何在iphone應用程序中關閉我的應用程序
- 5. 在iPhone中關閉報警偶數應用程序
- 6. 是否可以在應用程序中關閉設備(iPhone/iPad)?
- 7. 在Android應用程序中關閉ByteArrayOutputStream
- 8. UIPlerter關閉UIPicker後彈出
- 9. 在應用程序設置中(應用程序已關閉)
- 10. 關閉Android應用程序
- 11. Android應用程序關閉
- 12. 關閉Clickonce應用程序
- 13. 應用程序被關閉
- 14. 關閉的應用程序
- 15. 應用程序池關閉
- 16. 關閉應用程序
- 17. 關閉Windows應用程序
- 18. 關閉應用程序
- 19. 做什麼,即使應用程序關閉在iphone
- 20. iphone:在應用程序關閉時解析。
- 21. iPhone應用程序在關閉時發送數據
- 22. iPhone應用程序在啓動後立即關閉
- 23. iPhone應用程序崩潰在關閉/重新打開
- 24. 如何在進入後臺時關閉iPhone應用程序?
- 25. WatchKit從iPhone中的關閉應用程序獲取數據
- 26. 關閉iPhone應用程序中的聲音
- 27. iPhone應用程序應該關閉,不會去後臺
- 28. 關閉iPhone應用程序的動畫,如快門相機應用程序
- 29. 可以通過編程方式關閉iphone應用程序
- 30. 關閉iOS電源按鈕關閉應用程序關閉