Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UISearchBar-范围栏已设置动画_Iphone_Ios_Uisearchbar_Animated - Fatal编程技术网

Iphone UISearchBar-范围栏已设置动画

Iphone UISearchBar-范围栏已设置动画,iphone,ios,uisearchbar,animated,Iphone,Ios,Uisearchbar,Animated,我在“UISearchDisplayDelegate协议参考”下找到了带有范围栏的动画搜索栏示例( ),这里是视频预览: 我检查了示例代码,但找不到触发动画的代码。 有人知道如何制作动画吗?您必须使用UISearchBarDelegate才能获得动画吗?它内置于UISearchBar中。苹果为你做这件事,你不必自己调用任何方法 基本上,从您设置搜索栏的ScopeButtonTiles属性的那一刻起,苹果就会为范围栏设置动画。它内置在UISearchBar中。苹果为你做这件事,你不必自己调用任何

我在“UISearchDisplayDelegate协议参考”下找到了带有范围栏的动画搜索栏示例( ),这里是视频预览:

我检查了示例代码,但找不到触发动画的代码。
有人知道如何制作动画吗?您必须使用UISearchBarDelegate才能获得动画吗?

它内置于
UISearchBar
中。苹果为你做这件事,你不必自己调用任何方法


基本上,从您设置搜索栏的
ScopeButtonTiles
属性的那一刻起,苹果就会为范围栏设置动画。

它内置在
UISearchBar
中。苹果为你做这件事,你不必自己调用任何方法


基本上,从您设置搜索栏的
ScopeButtonTiles
属性的那一刻起,苹果将为范围栏设置动画。

我发现这个问题的答案更有用,尽管它不会自动将搜索栏转换到视图的顶部


我发现这个问题的答案更有用,尽管它不会自动将搜索栏转换到视图的顶部


为了控制UISearchBar的动画,您已经通过扩展头文件实现了UISearchDisplayController的委托。代表如下:

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
        [UIView beginAnimations:nil context:NULL];
        self.searchDisplayController.searchBar.showsScopeBar = NO;
        CGRect headerViewFrame = self.searchDisplayController.searchBar.frame;
        headerViewFrame.origin.y -= 54.0f;
        self.searchDisplayController.searchBar.frame = headerViewFrame;

        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.origin.y -= 54.0f;
        self.tableView.frame = tableViewFrame;

        [UIView commitAnimations];
    }

    -(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
    {
        [UIView beginAnimations:nil context:NULL];

        CGRect headerViewFrame = self.searchDisplayController.searchBar.frame;
        headerViewFrame.origin.y += 54.0f;
        self.searchDisplayController.searchBar.frame = headerViewFrame;

        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.origin.y += 54.0f;
        self.tableView.frame = tableViewFrame;

        [UIView commitAnimations];
    }

为了控制UISearchBar的动画,您已经通过扩展头文件实现了UISearchDisplayController的委托。代表如下:

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
        [UIView beginAnimations:nil context:NULL];
        self.searchDisplayController.searchBar.showsScopeBar = NO;
        CGRect headerViewFrame = self.searchDisplayController.searchBar.frame;
        headerViewFrame.origin.y -= 54.0f;
        self.searchDisplayController.searchBar.frame = headerViewFrame;

        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.origin.y -= 54.0f;
        self.tableView.frame = tableViewFrame;

        [UIView commitAnimations];
    }

    -(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
    {
        [UIView beginAnimations:nil context:NULL];

        CGRect headerViewFrame = self.searchDisplayController.searchBar.frame;
        headerViewFrame.origin.y += 54.0f;
        self.searchDisplayController.searchBar.frame = headerViewFrame;

        CGRect tableViewFrame = self.tableView.frame;
        tableViewFrame.origin.y += 54.0f;
        self.tableView.frame = tableViewFrame;

        [UIView commitAnimations];
    }

这对我来说在Xcode 6中非常有效。如果您已经设置了自动布局约束,那么您可能需要像我所做的那样为它们添加调整(没有它们就无法工作)


这对我来说在Xcode 6中非常有效。如果您已经设置了自动布局约束,那么您可能需要像我所做的那样为它们添加调整(没有它们就无法工作)

在动画块中调整大小
ui搜索栏
w/范围栏很容易设置动画。在使用范围栏调用sizeToFit之前,UISearchBar的高度为44.f,然后变为88.f。在我的例子中,
UISearchBar
被嵌入到Interface Builder中的
UITableView
中,因此无法添加自动布局约束

#pragma mark - UISearchBarDelegate methods

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    searchBar.showsScopeBar = YES;
    [UIView animateWithDuration:0.2f animations:^{
        [searchBar sizeToFit];
    }];

    [searchBar setShowsCancelButton:YES animated:YES];

    return YES;
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    searchBar.showsScopeBar = NO;
    [searchBar sizeToFit];

    [searchBar setShowsCancelButton:NO animated:YES];

    return YES;
}
在动画块中调整大小
ui搜索栏
w/范围栏很容易设置动画。在使用范围栏调用sizeToFit之前,UISearchBar的高度为44.f,然后变为88.f。在我的例子中,
UISearchBar
被嵌入到Interface Builder中的
UITableView
中,因此无法添加自动布局约束

#pragma mark - UISearchBarDelegate methods

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    searchBar.showsScopeBar = YES;
    [UIView animateWithDuration:0.2f animations:^{
        [searchBar sizeToFit];
    }];

    [searchBar setShowsCancelButton:YES animated:YES];

    return YES;
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    searchBar.showsScopeBar = NO;
    [searchBar sizeToFit];

    [searchBar setShowsCancelButton:NO animated:YES];

    return YES;
}

您必须在哪里添加UISearchBar?我已经将它添加到了tableView中,但当我单击它时,它并没有向上移动到导航标题。您是否必须调用“searchBar.showscopebar=YES;”来显示范围栏(动画)?我想您正在这里寻找我的答案:您必须在哪里添加UISearchBar?我已经将它添加到了tableView中,但当我单击它时,它并没有向上移动到导航标题。您是否必须调用“searchBar.showscopebar=YES;”来显示范围栏(动画)?我想您正在这里寻找我的答案:searchDisplayController在iOS8中没有被弃用,取而代之的是searchController。你有没有办法处理一个与iOS7+@popei兼容的搜索栏,仍然在寻找这个呢?在iOS8中,searchDisplayController并没有被弃用,取而代之的是searchController。你有没有办法处理一个与iOS7+@popei兼容的搜索栏,现在还在寻找这个?