2012-10-04 10 views
7

मैंने setInputAccessoryView का उपयोग कर कीबोर्ड के शीर्ष पर बटन के साथ एक दृश्य जोड़ा है। अब मैं कार्यक्षमता चाहता हूं जैसे कि जब मैं दृश्य से बटन क्लिक करता हूं, तो मैं कीबोर्ड के शीर्ष पर पिकर व्यू प्रदर्शित करना चाहता हूं। कीबोर्ड के सबव्यूव के रूप में पिकर व्यू जोड़ने जैसा मतलब है।कीबोर्ड के शीर्ष पर एक दृश्य कैसे जोड़ें?

मैं यह कैसे कर सकता हूं?

+0

क्या आपके पास ऐसा ऐप्स हैं जो ऐसा करते हैं? – Jessedc

उत्तर

1

आप पहली बार एक और UIWindow बनाने की जरूरत:

UIWindow *newWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,100,320,20)]; 
newWindow.windowLevel = UIWindowLevelStatusBar; // this will make to place your WINDOW above the keyboard 
[newWindow makeKeyAndVisible]; // show the new window 

// [newWindow addSubview:yourView]; 
+0

'UIWindow * newWindow = [[UIWindow alloc] initWithFrame: CGRectMake (0.0, 250, 320, 200)]; newWindow.windowLevel = UIWindowLevelStatusBar; [newWindow makeKeyAndVisible]; [newWindow addSubview: self.myView]; 'लेकिन यह काम नहीं कर रहा है। – user1244311

+0

वर्णन: यह काम नहीं कर रहा है .. :) –

1

चाहते कीबोर्ड पर बटन जोड़ने आप भी bellow तरह दृश्य जोड़ सकते हैं ...

यहाँ आप कीबोर्ड की खिड़की खोजने के लिए और फिर बटन के फ्रेम सेट और यह भी yourView और फिर कीबोर्ड को जोड़ने के

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardDidShow:) 
               name:UIKeyboardDidShowNotification 
               object:nil]; 
    return YES; 
} 
- (void)keyboardDidShow:(NSNotification *)note { 
    UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    returnBtn.frame = CGRectMake(0,-25,320,25); 
    returnBtn.adjustsImageWhenHighlighted = NO; 
    returnBtn.backgroundColor=[UIColor darkGrayColor]; 
    returnBtn.titleLabel.textColor=[UIColor whiteColor]; 
    [returnBtn setBackgroundImage:[UIImage imageNamed:@"keyBtn.png"] forState:UIControlStateNormal]; 

    [returnBtn addTarget:self action:@selector(keyboardBtn:) forControlEvents:UIControlEventTouchUpInside]; 
    // locate keyboard view 
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; 
    UIView* keyboard; 
    for(int i=0; i<[tempWindow.subviews count]; i++) { 
     keyboard = [tempWindow.subviews objectAtIndex:i]; 
     // keyboard found, add the button 
     if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) 
      // if (txtTag==5) { 
      [keyboard addSubview:returnBtn]; 
    } 
} 
-(IBAction)keyboardBtn:(id)sender{ 
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; 
    UIView* keyboard; 
    for(int i=0; i<[tempWindow.subviews count]; i++) { 
     keyboard = [tempWindow.subviews objectAtIndex:i]; 
     // keyboard found, add the button 
     if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) 
      // if (txtTag==5) { 
      [keyboard addSubview:yourView];// here add your view with frame 
    } 
} 

मैं इस मदद आशा है कि आप ...

:)

2
self.pickerContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 194, 320, 224)]; 
    self.pickerContainerView.backgroundColor = [UIColor clearColor]; 
    [self.view addSubview:self.pickerContainerView]; 

    UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; 
    pickerToolbar.barStyle = UIBarStyleBlackTranslucent; 
    [pickerToolbar sizeToFit]; 

    self.lblPickerViewTitle = [[UILabel alloc] initWithFrame:CGRectMake(15, 7, 230, 30)]; 
     self.lblPickerViewTitle.backgroundColor = [UIColor clearColor]; 
    [self.lblPickerViewTitle setFont: [UIFont fontWithName:@"Arial-BoldMT" size:17]]; 
     self.lblPickerViewTitle.textAlignment = UITextAlignmentLeft; 
     self.lblPickerViewTitle.textColor =[UIColor whiteColor]; 
    [pickerToolbar addSubview:self.lblPickerViewTitle]; 

    NSMutableArray *barItems = [[NSMutableArray alloc] init]; 
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 
    [barItems addObject:flexSpace]; 
    [flexSpace release]; 

    UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(closePickerView:)]; 
    [barItems addObject:btnCancel]; 
    [btnCancel release]; 

    UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] initWithTitle:@"ShowPicker" style:UIBarButtonItemStyleBordered target:self action:@selector(donePickerView:)]; 
    [barItems addObject:btnDone]; 
    [btnDone release]; 

    [pickerToolbar setItems:barItems animated:YES]; 
    [barItems release]; 
    [self.pickerContainerView addSubview:pickerToolbar]; 

और में ShowPicker विधि, प्रदर्शन UIPicker

+0

मेरी समस्या यह है कि मैं अपने दृश्य के सबव्यू के रूप में pickerView जोड़ने में सक्षम हूं लेकिन कुंजी बोर्ड छुपा रहा है। तो जब मैं बटन पर क्लिक करता हूं तो मैं चाहता हूं कि मैं कीबोर्ड के शीर्ष पर पिकर व्यू प्रदर्शित करना चाहता हूं। – user1244311

+0

आपकी समस्या कीबोर्ड प्रदर्शित नहीं होती है और आप अपने keyboed पर pickerview प्रदर्शित करने के लिए wn ??? मैं सही हूँ ?? –

+0

मैंने कीबोर्ड के शीर्ष पर एक दृश्य जोड़ा है। उस दृश्य में बटन हैं। जब मैं एक बटन क्लिक करता हूं तो मैं कीबोर्ड के स्थान पर एक पिकर दृश्य प्रदर्शित करना चाहता हूं। लेकिन समस्या यह है कि कीबोर्ड में दृश्य जोड़ा जाता है। इसलिए यदि आप कीबोर्ड को छुपाते हैं तो बटन दृश्य भी छुपाया जाएगा। – user1244311

19

के लिए कोड लिखने कीबोर्ड के शीर्ष पर एक दृश्य आप चाहते हैं। आप इसे xib या मैन्युअल रूप से कर सकते हैं, लेकिन मुझे लगता है कि xib एक बेहतर विकल्प होगा।

फिर इस

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    textField.inputAccessoryView = YOURCustomView; 
    return YES; 
} 

करके इस दृश्य का संदर्भ देते जब भी आपको यह छिपाने या इसे निकाल सिर्फ जोनास Schnelli के जवाब से यह

textField.inputAccessoryView = nil; 
0

रखना चाहते हैं

UIWindow *newWindow = [[UIWindow alloc]initWithFrame:CGRectMake(0,100,320,20)]; 
newWindow.windowLevel = CGFLOAT_MAX; // this will make to place your WINDOW above the keyboard 

[newWindow addSubview:yourView]; 

बस UIWindowLevelStatusBar से CGFLOAT_MAX बदलें ठीक है।

संबंधित मुद्दे