Sho*_*uit 35 iphone keyboard animation
前一段时间我记得看到一种常量定义了iPhone上键盘的动画速率,我不能为我的生活记住我在哪里看到它......任何见解?
Sha*_*rog 68
- (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification*)notification
{
NSDictionary* info = [notification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 0;
[value getValue:&duration];
return duration;
}
Run Code Online (Sandbox Code Playgroud)
Zhe*_*ing 16
UIKeyboardAnimationDurationUserInfoKey现在是一个NSNumber对象,它使代码更短.
- (void)keyboardWillShowNotification:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
NSNumber *number = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
double duration = [number doubleValue];
}
Run Code Online (Sandbox Code Playgroud)
小智 11
由于这是第一个谷歌热门,我想指出,硬编码0.3意味着当国际用户(例如日语)在不同大小的键盘之间切换时(当该动作应该是即时的)时,您的视图将会错误地生成动画. .
始终使用通知的userInfo字典的UIKeyboardAnimationDurationUserInfoKey值 - 当用户轻击键盘时,它将设置为0.
再加上Shaggy Frog所写的内容.完整的实现将是这样的:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardMovement:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardMovement:)
name:UIKeyboardWillHideNotification
object:nil];
-(void)keyboardMovement:(NSNotification *)notification{
if (_numericKeyboardShowing == false){
[UIView animateWithDuration:[self keyboardAnimationDurationForNotification:notification] delay:0
options:UIViewAnimationCurveEaseInOut
animations:^ {
self.bottomContainerView.center = CGPointMake(self.bottomContainerView.center.x, (self.bottomContainerView.center.y - 218));
}
completion:NULL];
_numericKeyboardShowing = true;
}
else{
[UIView animateWithDuration:[self keyboardAnimationDurationForNotification:notification] delay:0
options:UIViewAnimationCurveLinear
animations:^ {
self.bottomContainerView.center = CGPointMake(self.bottomContainerView.center.x, (self.bottomContainerView.center.y + 218));
}
completion:NULL];
_numericKeyboardShowing = false;
}
- (NSTimeInterval)keyboardAnimationDurationForNotification:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
NSValue* value = [info objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval duration = 0;
[value getValue:&duration];
return duration;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26843 次 |
| 最近记录: |