1
我在學習過程中,我有這個特定的代碼,只要我們點擊文本框或textview屏幕向上移動,當我們退出鍵盤屏幕到達其原始位置時,它對於橫向和縱向模式均可正常工作如何將y軸設置爲0,如果屏幕超出了原始屏幕或屏幕下方 - 在iPad
問題是什麼。最初它是在肖像模式下,當我們點擊文本框或文本視圖時,屏幕正在擡起並顯示鍵盤,現在當我旋轉到橫向並退出鍵盤時,屏幕正在向下移動,反之亦然。
- (void)animateTextField:(UITextField*)textField textView:(UITextView *)textView up:(BOOL)up{
int animatedDistance;
int moveUpValue;
if (textField) {
moveUpValue = textField.frame.origin.y+ textField.frame.size.height;
}
else {
moveUpValue = textView.frame.origin.y+ textView.frame.size.height;
}
NSLog(@"moveup%d",moveUpValue);
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait ||
orientation == UIInterfaceOrientationPortraitUpsideDown)
{
if(textField){
animatedDistance = 216-(650-moveUpValue-5);
}
else{
animatedDistance = 216-(850-moveUpValue-5);
}
}
else
{
if(textField){
animatedDistance = 162-(505-moveUpValue-5);
}
else{
animatedDistance = 162-(750-moveUpValue-5);
}
}
NSLog(@"animated%d",animatedDistance);
if(animatedDistance>0)
{
const int movementDistance = animatedDistance;
const float movementDuration = 0.3f;
int movement = (up ? -movementDistance : movementDistance);
NSLog(@"movement portrait%d",movement);
[UIView beginAnimations: nil context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
scrollview.frame = CGRectOffset(scrollview.frame, 0, movement);
[UIView commitAnimations];
}
}
我想現在我該如何解決這個問題,或者怎樣才能改變y軸爲0
請您做的幫助。 在前提前感謝
您可以使用方向委託方法按照新方向更新animatedDistance。所以當你辭職鍵盤時,animatedDistance將按照currentOrientation。 – Ravin
請參考以下鏈接你的答案.. http://stackoverflow.com/questions/8090063/how-to-manage-application-when-orientation-changes/8090119#8090119 –
我已經使用了,和 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { //返回YES用於支撐取向 如果(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ [自portraitFrames]; } else { [self landscapeFrames]; } return YES; } – iYahoo