我有一個簡單的UITextField
,當有人去編輯它,並彈出鍵盤時,視圖向上移動,以便用戶可以看到他們進入的東西。但是,當我關閉鍵盤時,視圖不會回到原來的位置!我正在使用CGPoint
屬性捕獲其在viewDidLoad
上的原始位置,然後在鍵盤關閉時嘗試將其重新設置爲該位置。UIView在動畫後沒有回到正確的位置
代碼:
- (void)viewDidLoad {
[super viewDidLoad];
// Set the original center point for shifting the view
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
self.originalCenter = self.view.center;
}
- (void)doneWithNumberPad {
[locationRadius resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.center = self.originalCenter;
[UIView commitAnimations];
}
- (void)keyboardDidShow:(NSNotification *)note
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.center = CGPointMake(self.originalCenter.x, 150);
[UIView commitAnimations];
}
好東西我不支持自動旋轉! – 2013-02-22 21:34:40