내 응용 프로그램에서는 UITextField에서 키보드가 나타난 후 내 ViewController의 뷰를 위쪽 방향으로 움직이거나 움직이지 않아도됩니다.iOS 7 iPad 키보드가 UITextField에 나타난 후 뷰가 위쪽으로 움직일 때의 오리엔테이션 문제
이 모든 orientation.i.e에 대한 지원해야합니다
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight합니다.
을하지만 UIInterfaceOrientationPortraitUpsideDown 및 UIInterfaceOrientationLandscapeLeft 것이를 작동하지 않습니다 : 아래 그림과 같이 UIInterfaceOrientationPortrait를 들어
내 코드는 잘 작동한다. 스크린 아래 참조주세요 UIInterfaceOrientationLandscapeLeft 뷰
상방 측 대신 오른쪽을 향해 이동한다.
아래쪽 대신 측 상방을 향해 UIInterfaceOrientationPortraitUpsideDown 뷰 이동을위한
.
이 내가 아이폰 OS 8에서이 문제를 확인했습니다 아이폰 OS 7 만 문제가
, 그것은 잘 작동합니다.나는 키보드 모양에 UIView의 애니메이션에 대한 코드 아래 사용했다 :
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 264;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 352;
-(void) textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION * viewRect.size.height;
CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION) * viewRect.size.height;
CGFloat heightFraction = numerator/denominator;
if (heightFraction < 0.0)
{
heightFraction = 0.0;
}
else if (heightFraction > 1.0)
{
heightFraction = 1.0;
}
UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT * heightFraction);
}
else
{
animatedDistance = floor(LANDSCAPE_KEYBOARD_HEIGHT * heightFraction);
}
if(self.view.frame.origin.y != 0.000000)
{
self.view.frame = CGRectMake(self.view.frame.origin.x,0.0,self.view.frame.size.width,self.view.frame.size.height);
}
CGRect viewFrame = self.view.frame;
viewFrame.origin.y -= animatedDistance;
NSLog(@"View frame y pos did start: %f ",animatedDistance);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
-(void) textFieldDidEndEditing:(UITextField *)textField
{
CGRect viewFrame = self.view.frame;
viewFrame.origin.y += animatedDistance;
NSLog(@"View frame y pos did end: %f ",animatedDistance);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
[self.view setFrame:viewFrame];
[UIView commitAnimations];
}
감사
답장을 보내 주셔서 감사합니다. 당신의 솔루션이 정말로 도움이되었습니다. –
쿨! 이 XCode 지옥으로 발견 한 한 가지 ... 작동 예제를 볼 때 삶이 훨씬 쉬워집니다! 기쁜 데 도움이되었습니다. –