• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 让线程进入休眠状态,但让动画继续播放 - 这可能吗?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:20:08 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

这可能是一个奇怪的问题,但对于我想要实现的目标可能会有不同的解决方案,我愿意接受任何需要的东西!

事实:

我有一个 UITableView 和一个由 UISearchDisplayController 处理的 UISearchBar

上面说TableView 我有一些按钮和一个小的UIScrollView

当用户点击 SearchBar 并且键盘出现时,在键入时显示搜索结果的空间非常小。

因此,当用户开始搜索时,我想将 TableView 一直移动到顶部(覆盖按钮和 ScrollView)。

我的代码和问题:

- (void)searchDisplayControllerWillBeginSearchUISearchDisplayController *)controller {
...

[UIView beginAnimations"Search" context:nil];
[UIView setAnimationDuration:0.6];
[self.attractionsTableView setFrame:CGRectMake(0, 0, 320, 400)];
[UIView commitAnimations];

...
return;

}

现在的问题是,由于我的 UITableView 必须移动的距离约为 100 点,SearchDisplayController 将黑色覆盖层放在 TableView 顶部会更快,因此黑色覆盖层已经打开顶部,而 TableView 仍在向上滑动。

结果是一个看起来有点像这样的屏幕:

problem http://img833.imageshack.us/img833/9186/problemqdu.png

所以用户看到 TableView 向上滑动(这很好),但黑色覆盖层已经在那里等待,因为 searchDisplayController 的动画比我的快。

所以我有一个可能的想法,但不知道该怎么做:

有没有办法设置 searchDisplayController 的动画持续时间,将黑色覆盖层放在搜索 tableView 的顶部?

编辑:

我知道我可以将 animationDuration 设置为 0.01 甚至 0,但是 0.6 的速度对于 100 点的距离来说似乎还不错,所以我正在尝试寻找一种不同的解决方案来降低持续时间。



Best Answer-推荐答案


诀窍是在动画完成之前不要让运行循环正常运行。当运行循环在特定模式下运行时会执行动画。幸运的是,叠加动画在不同的运行循环模式下执行,而不是在默认运行循环模式下运行的其他动画。所以,你所要做的就是在你的方法中运行 run loop,直到动画完成。

- (void)searchDisplayControllerWillBeginSearchUISearchDisplayController *)controller {
    BOOL done = NO;
    // Pass the done variable's address as the context so we can be notified
    [UIView beginAnimations"SearchExpand" context:&done];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelectorselector(animationDone:finished:context];
    [UIView setAnimationDuration:0.6];
    // Expend the table view to fill its superview
    self.attractionsTableView.frame = [[self.attractionsTableView superview] bounds];
    [UIView commitAnimations];
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    // Run the run loop until the animation completes
    while(!done) {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        if(![runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]])
            break;
        [pool drain];
    }
}

- (void)animationDoneNSString *)name finishedNSNumber *)finished contextvoid *)context {
    // Set the done flag to YES
    *((BOOL*)context) = YES;
    // and kill the run loop
    CFRunLoopStop(CFRunLoopGetCurrent());
}

关于ios - 让线程进入休眠状态,但让动画继续播放 - 这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590194/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap