프로그래밍 방식으로 정렬하는 도구 모음에서 최고의 아이폰의 키보드
-
03-07-2019 - |
문제
에서 여러 경우를 추가하려면 도구 모음의 상단 아이폰 키보드(로에서는 아이폰 사파리를 탐색할 때 형태소,예를 들어).
현재 내가 지정하는 도구 모음의 사각형 상수 그러나기 때문에 다른 요소의 인터페이스에서 유출 탐색 도구모음과 바에서 최고의 화면을 때마다 우리는 사소한 인터페이스 변경,도구 모음의 정렬.
는 방법이 있을 프로그래밍 방식으로 위치를 결정의 키보드와 관련하여 현재 보?
해결책
으로 iOS3.2 있는 새로운 방법이 효과를 달성하기:
UITextFields
고 UITextViews
가 inputAccessoryView
속성을 설정할 수 있는 모든기,자동으로 표시되는 위와 애니메이션한 결과를 조회할 수 있습니다.
참고 보면 사용하는 한도에서 보기 계층 구조,다른 곳에서나 해야 당신이 그것을 추가 어떤 뷰,이것은 당신을 위해 수행됩니다.
다른 팁
그래서 기본적으로:
에서 초기화 방법:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
다음 방법 위에서 언급하의 위치를 조정됩:
-(void) keyboardWillShow:(NSNotification *) note
{
CGRect r = bar.frame, t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
r.origin.y -= t.size.height;
bar.frame = r;
}
수여 애니메이션을 위치를 변경에 배치
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
//...
[UIView commitAnimations];
이에 따라 기존의 응답에서 tonklon -나는 단지 추가 코드 조각을 보여주는 반투명 검은 도구 모음에서 최고의 키보드,함께"done"버튼을 오른쪽에:
UIToolbar *toolbar = [[[UIToolbar alloc] init] autorelease];
[toolbar setBarStyle:UIBarStyleBlackTranslucent];
[toolbar sizeToFit];
UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneButton =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resignKeyboard)];
NSArray *itemsArray = [NSArray arrayWithObjects:flexButton, doneButton, nil];
[flexButton release];
[doneButton release];
[toolbar setItems:itemsArray];
[aTextField setInputAccessoryView:toolbar];
고 -resignKeyboard
처럼 보인:
-(void)resignKeyboard {
[aTextField resignFirstResponder];
}
희망하는 누군가가 도움이 됩니다.
등록하는 경우 키보드에 대한 알림을,즉 UIKeyboardWillShowNotification
UIKeyboardWillHideNotification
, 등,알림을 받을 것을 포함한 범위의 키보드에서 userInfo
dict(UIKeyboardBoundsUserInfoKey
).
보 UIWindow
클래스에 참조.
에서 3.0 이상을 얻을 수 있는 애니메이션 기간 곡선에서 userInfo
사전의 통지.
예를 들어,애니메이션의 크기를 보기위한 공간을 만들기 위해 키보드,등록 UIKeyboardWillShowNotification
고지식은 다음과 같습니다.
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:[[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]];
[UIView setAnimationDuration:[[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
CGRect frame = self.view.frame;
frame.size.height -= [[[notification userInfo] objectForKey:UIKeyboardBoundsUserInfoKey] CGRectValue].size.height;
self.view.frame = frame;
[UIView commitAnimations];
}
하와 유사한 애니메이션 UIKeyboardWillHideNotification
.
내가 찾는 이 링크를 이해하는 것이 매우 유용하 inputaccesoryview step by step.
이 메소드 호출에 ViewWillLoad:
- (void) keyboardToolbarSetup
{
if(self.keyboardToolbar==nil)
{
self.keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(anyAction)];
UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(anyOtherAction)];
NSArray *toolbarButtons = [[NSArray alloc]initWithObjects:cancelButton,extraSpace,doneButton, nil];
[self.keyboardToolbar setItems:toolbarButtons];
self.myTextView.inputAccessoryView=self.keyboardToolbar;
}
}
방법이 없(AFAIK)을 얻을 수 차원의 키보드 보기입니다.그것은 그러나,일정에서 적어도는 모든 아이폰 버전이 지금까지.
계산하면 도구 모음의 위치는 오프셋의 바닥에서 당신의 보고,크기 보기 계좌로,당신은 없어야 한다는 걱정할지 여부를 메뉴 바로 존재하거나지 않습니다.
E.g.
#define KEYBOARD_HEIGHT 240 // example - can't remember the exact size
#define TOOLBAR_HEIGHT 30
toolBarRect.origin.y = viewRect.size.height - KEYBOARD_HEIGHT - TOOLBAR_HEIGHT;
// move toolbar either directly or with an animation
신의 정의,당신은 쉽게 만들기 keyboardHeight
기능는 크기를 반환하는지 여부를 기반으로 키보드에 표시되고,그리고 움직이는 도구 모음 위치 지정으로 별도의 기능을 둔 당신의 레이아웃이 있습니다.
또한 그에 따라 달라질 수 있습는 당신이 이렇게 위로 가능한 크기의 보 변경될 수 있습 사이 로딩되는 표시에 따라 메뉴 바 setup.내가 믿는 최고의 장소는 그것을 할 것에 viewWillAppear.