2011-09-21 25 views
0

其實我有一個文本字段。KeyBoard隱藏方法我需要動畫嗎?

其目的是使用視圖和滾動視圖來顯示和隱藏鍵盤。

一切都很好,但每當鍵盤隱藏視圖下降沒有任何動畫。我的意思是它非常快,在我的iphone上看起來不錯。

我想視圖慢慢倒下。

對於主要是我使用這個代碼..

CGPoint p=CGPointMake(0,0); 
[srlvJuiceandSmoothireDetail1 setContentOffset:p animated:YES]; 

我可以設置動畫的持續時間,其實我也是不知道,這種方法是值得與否。

在鍵盤上顯示這是值得...

一些Code..for refrence ...

- (void) keyboardDidHide:(NSNotification *)notif { 
    if (!keyboardVisible_) { 
     NSLog(@"%@", @"Keyboard already hidden. Ignoring notification."); 
     return; 
    } 

// CGRect viewFrame = scrlView; 
    srlvJuiceandSmoothireDetail1.frame = scrlView; 
    CGPoint p=CGPointMake(0,0); 
    [srlvJuiceandSmoothireDetail1 setContentOffset:p animated:YES]; 

    keyboardVisible_=NO; 

    } 

回答

2

能夠繪製某些UIView屬性,包括框架。有關如何完成的更多信息,請參閱UIView的文檔。

這裏就是你可能想:

NSTimeInterval duration = [[[notif userInfo] valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; 

[UIView animateWithDuration:duration animations: 
^{ 
    srlvJuiceandSmoothireDetail1.frame = scrlView; 
}]; 
+0

感謝它很好.... –

+0

但UIKeyboardAnimationDurationUserInfoKey不工作,所以,我已經手動設置它.. –

0

你嘗試隱藏鍵盤是這樣的: 創建你的方法查看:

-(IBAction)hideKeyboard:(id)sender 
{ 
    [*Your text filed* resignFirstResponder]; 
} 

默認情況下它使得鍵盤隱藏動畫。 對不起,如果我不明白你的問題是正確的。

0

其實上面的回答和通知,如果我們使用UIKeyboardWillShow會工作,而不是

UIKeyboardDidShow在一起很好。

另外我已經手動設置了持續時間。