iPhone의 새로운 기술입니다. iPhone 응용 프로그램에서 문제를 저장했지만 텍스트 필드 키보드 유형 번호 패드를 사용하면 키보드에 return/done 버튼이 표시되지 않습니다.숫자 패드 키보드가 표시되지 않습니다.
텍스트 필드에 숫자를 입력 한 후 숫자 패드 키보드를 숨기려면 어떻게합니까? 그 해결책이 있습니까? 도움을주십시오.
iPhone의 새로운 기술입니다. iPhone 응용 프로그램에서 문제를 저장했지만 텍스트 필드 키보드 유형 번호 패드를 사용하면 키보드에 return/done 버튼이 표시되지 않습니다.숫자 패드 키보드가 표시되지 않습니다.
텍스트 필드에 숫자를 입력 한 후 숫자 패드 키보드를 숨기려면 어떻게합니까? 그 해결책이 있습니까? 도움을주십시오.
:
@property (nonatomic, strong) UITextField *textField;
- (void)viewDidLoad {
[super viewDidLoad];
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonDidPressed:)];
UIBarButtonItem *flexableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[self class] toobarHeight])];
[toolbar setItems:[NSArray arrayWithObjects:flexableItem,doneItem, nil]];
self.textField.inputAccessoryView = toolbar;
}
- (void)doneButtonDidPressed:(id)sender {
[self.textField resignFirstResponder];
}
+ (CGFloat)toolbarHeight {
// This method will handle the case that the height of toolbar may change in future iOS.
return 44.f;
}
숫자 패드에는 반품 또는 완료 키가 없습니다. 사용자가 텍스트 필드 외부를 터치하면 키보드를 숨길 수 있습니다. 당신은 이런 식으로 뭔가해야 - 당신이 UIKeyboardTypeNumberPad을 사용하고 있어야합니다
if (there is a touch outside of your textField)
{
[textField resignFirstResponder];
}
을, 그것은 단지 리턴 키를 표시하지 것 대신 UIKeyboardTypeNumbersAndPunctuation, 을이 시도하지만이 질문은이 몇 가지 추가 구두점
을 제공 이미 답을 얻었습니다. 왜냐하면 그게 해결책을 얻었 기 때문입니다. 2 가지 옵션이 있습니다. 첫 번째는 "완성 된 편집"메시지를 보낼 메인 뷰에 터치를 구현하여 키보드를 숨기는 것입니다. that 키보드를 숨 깁니다 [self.view endEditing : YES];
터치 리스너를 메인 뷰에 추가하는 경우 다른 버튼이 계속 작동 할 수 있도록 조건을 구현해야합니다. 키보드에 대한
등록이 쇼 통지를했고, 코드에 이것을 추가 :
if ([self.passCodeLabel isFirstResponder])
{
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
//doneButton.frame = CGRectMake(0, 163, 257, 257);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
NSLog(@"%@",[[UIApplication sharedApplication] windows]);
UIView* keyboard;
NSLog(@"Shared applicaiton windows count:%i",tempWindow.subviews.count);
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
NSLog(@"%@",[keyboard description]);
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIPeripheralHostView"] == YES)
{
NSLog(@"Adding return button");
[keyboard addSubview:doneButton];
}
}
}
이 의지 당신이 리턴 키를 시뮬레이션하기 위해 수행 할 작업은 무엇
실제로이 같은 추가하는 것입니다 자신 만의 "완료"버튼 이미지를 키보드에 추가하십시오 (공백 슬롯의 스크린 샷을 찍고 완성 된 텍스트를 추가하여 복사 할 수 있습니다).
Btw 내가 레이아웃에 붙여 넣은 코드입니다. 귀하의 경우 약간 수정해야하지만 원칙은 동일합니다.
이 서브 뷰에있는 버튼을 추가 버튼을 키보드 서브 뷰
에 대한
모양을 만들
이 방법으로이 작업을 수행 할 수 있습니다- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
_txt_mobileno.inputAccessoryView = numberToolbar;
}
-(void)doneWithNumberPad
{
[_txt_mobileno resignFirstResponder];
}
iOS 6.1의 경우 툴바를 초기화하지 않으면 작동하지 않습니다. UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame : CGRectMake (0, 0, self.view.bounds.size.width, 44)];'그렇지 않으면, 완벽한 응답 – Segfault
@Segfault 그 것을 확인하십시오. 6.1에서 제대로 작동하려면 프레임을 지정해야합니다. – Paul
감사합니다. Segfault, 수정하겠습니다. – Oscar