iOS 7 - 键盘动画 [英] iOS 7 - Keyboard animation

查看:100
本文介绍了iOS 7 - 键盘动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iPhone 5模拟器上了解iOS 7.0中的新键盘动画。我想在键盘出现时调整我的 UITableView ,但我无法获得正确的动画细节。

我正在使用来自当键盘出现或消失时, NSNotification 对象。



这是我的日志:

 将键盘从{{0,920},{320,216}}移至{{0,352},{320,216}} 
持续时间:0.400000
和动画曲线:7

UIViewAnimationCurveEaseInOut = 0
UIViewAnimationCurveEaseIn = 1
UIViewAnimationCurveEaseOut = 2
UIViewAnimationCurveLinear = 3

动画曲线是未知值,我该怎么办?

解决方案

现在我找到了解决方案。动画从点 {0,920} 开始到 {0,352} 。问题是 UITableView 对象的起始大小为 {160,568} ,所以我改变了大小动画开始前, UITableView {160,920}



关于未知动画曲线,我只是将参数设置为 animationCurve<< 16 将它从视图动画曲线转换为视图动画选项。

该值不等于动画曲线的线性,缓入,缓和和缓和。 / p>

这是我的代码:

  [[NSNotificationCenter defaultCenter] addObserver: self 
selector:@selector(_keyboardWillShow :)
name:UIKeyboardWillShowNotification
object:nil];

和:

   - (void)keyboardWillShow:(NSNotification *)aNotification {
NSDictionary * userInfo = aNotification.userInfo;

//
//获取键盘大小。

NSValue * beginFrameValue = userInfo [UIKeyboardFrameBeginUserInfoKey];
CGRect keyboardBeginFrame = [self.view convertRect:beginFrameValue.CGRectValue fromView:nil];

NSValue * endFrameValue = userInfo [UIKeyboardFrameEndUserInfoKey];
CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];

//
//获取键盘动画。

NSNumber * durationValue = userInfo [UIKeyboardAnimationDurationUserInfoKey];
NSTimeInterval animationDuration = durationValue.doubleValue;

NSNumber * curveValue = userInfo [UIKeyboardAnimationCurveUserInfoKey];
UIViewAnimationCurve animationCurve = curveValue.intValue;

//
//创建动画。

CGRect tableViewFrame = self.tableView.frame;
bTableViewFrame.size.height =(keyboardBeginFrame.origin.y - tableViewFrame.origin.y);
self.tableView.frame = tableViewFrame;

void(^ animations)()= ^(){
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height =(keyboardEndFrame.origin.y - tableViewFrame.origin.y);
self.tableView.frame = tableViewFrame;
};

//
//开始动画。

[UIView animateWithDuration:animationDuration
delay:0.0
options:(animationCurve<< 16)
animations:animations
completion:nil];
}


I'm trying to understand the new keyboard animation in iOS 7.0 on the iPhone 5 Simulator. I want to resize my UITableView when the keyboard appears, but I can't get the right animation details.
I'm using the information from the NSNotification object, when the keyboard appears or disappears.

Here is my log:

Move keyboard from {{0, 920}, {320, 216}} to {{0, 352}, {320, 216}}
 with duration: 0.400000
 and animation curve: 7

UIViewAnimationCurveEaseInOut = 0
UIViewAnimationCurveEaseIn = 1
UIViewAnimationCurveEaseOut = 2
UIViewAnimationCurveLinear = 3

The animation curve is an unknown value, what should I do?

解决方案

Now I found the solution. The animation starts from the point {0, 920} to {0, 352}. The problem was that the UITableView object started with a size of {160, 568}, so I changed the size of the UITableView to {160, 920} before the animation was started.

Concerning to the unknown animation curve, I just set the parameter to animationCurve << 16 to convert it from a view animation curve to a view animation option.
The value is not equal to the linear, ease in, ease out and ease inout animation curve.

Here is my code:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(_keyboardWillShow:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];

and:

- (void)keyboardWillShow:(NSNotification *)aNotification {
    NSDictionary *userInfo = aNotification.userInfo;

    //
    // Get keyboard size.

    NSValue *beginFrameValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
    CGRect keyboardBeginFrame = [self.view convertRect:beginFrameValue.CGRectValue fromView:nil];

    NSValue *endFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardEndFrame = [self.view convertRect:endFrameValue.CGRectValue fromView:nil];

    //
    // Get keyboard animation.

    NSNumber *durationValue = userInfo[UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration = durationValue.doubleValue;

    NSNumber *curveValue = userInfo[UIKeyboardAnimationCurveUserInfoKey];
    UIViewAnimationCurve animationCurve = curveValue.intValue;

    //
    // Create animation.

    CGRect tableViewFrame = self.tableView.frame;
    bTableViewFrame.size.height = (keyboardBeginFrame.origin.y - tableViewFrame.origin.y);
    self.tableView.frame = tableViewFrame;

    void (^animations)() = ^() {
        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.size.height = (keyboardEndFrame.origin.y - tableViewFrame.origin.y);
        self.tableView.frame = tableViewFrame;
    };

    //
    // Begin animation.

    [UIView animateWithDuration:animationDuration
                          delay:0.0
                        options:(animationCurve << 16)
                     animations:animations
                     completion:nil];
}

这篇关于iOS 7 - 键盘动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆