动画在第一次运行时滞后

时间:2012-05-29 19:18:02

标签: iphone ios animation lag

使用以下代码对搜索栏进行动画处理:

- (IBAction)toggleSearchBar:(UIBarButtonItem *)sender{

CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:0.2];
[applicationLoadViewIn setType:kCATransitionPush];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

if (self.searchBar.hidden) {

    self.searchBar.hidden = NO;
    [self.searchBar becomeFirstResponder];

    [applicationLoadViewIn setSubtype:kCATransitionFromBottom];
    [[searchBar layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];

}else{

    self.searchBar.hidden = YES;
    [self.searchBar resignFirstResponder];

    [applicationLoadViewIn setSubtype:kCATransitionFromTop];
    [[searchBar layer] addAnimation:applicationLoadViewIn forKey:kCATransitionPush];

}
}

除了动画第一次运行时的延迟,它才能正常工作。无论如何要解决它吗?任何帮助将不胜感激:)

修改1

他leftBarButton连线到toggleSearchBar:行动。该应用已加载。第一个动画是第一次点击leftBarButton。

1 个答案:

答案 0 :(得分:0)

为什么不在加载视图控制器时将其显示在屏幕上...它有点hacky但它​​应该可以解决问题。