小编Tia*_*aia的帖子

UISearchController中的searchBar在tableHeaderView中动画出屏幕

我有一个UISearchControllerUITableViewController作为searchResultsController,在UISearchBar这个searchController设置是在tableHeaderView我目前的tableView在我的根视图控制器显示.正如预期的那样,几乎所有东西都运作良好.但是在动画中UISearchBar(当我点击searchBar和UINavigationBar隐藏并且searchBar到达顶部时,如同UISearchDisplayController)我有一个奇怪的行为.它不会移动到UINavigationBar(y:0)的位置,而是跳出屏幕而不是启动显示取消按钮的动画.我尝试将我的实例化代码移动到viewDidLoad而不是init,事情就是一样的.我认为问题的核心在于searchResultsController视图的框架,但我不确定(我尝试设置框架,但没有成功).我正在做的一切都是纯粹的代码.

以下是代码的相关部分:

- (void) viewDidLoad { 
    [super viewDidLoad];

    // search controller setup
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
    self.searchController.delegate = self;
    self.searchController.searchResultsUpdater = self;
    self.searchController.searchBar.delegate = self;

    [self.searchController.searchBar sizeToFit];
    self.tableView.tableHeaderView = self.searchController.searchBar;

    self.searchController.definesPresentationContext = YES;
}
Run Code Online (Sandbox Code Playgroud)

我有一个懒惰的负载searchResultsController:

- (UITableViewController *)searchResultsController {
    if (_searchResultsController == nil) {
        _searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview uisearchbar ios uisearchcontroller

30
推荐指数
5
解决办法
2万
查看次数

AlphaAnimation对象不更改被动画视图的alpha属性,为什么?

我正在尝试为按钮的Alpha设置动画,当我将Alpha从1设置为0时效果很好。但是,在动画的最后,我无法将其从0重置为1,因为按钮的Alpha已经存在1(这会使按钮仅在屏幕上“跳跃”而不褪色)。似乎Animation对象不是直接将视图设置为alpha,而是视图的某些表示属性。有谁知道如何使该动画正常工作?

我的代码:

private void performFavoriteButtonFade(boolean isFavorite) {
    AlphaAnimation fadeAnimation = new AlphaAnimation(0, 0);
    if (isFavorite) {
        if (this.favoriteButton.getAlpha() == 1) {
            fadeAnimation = new AlphaAnimation(1, 0);
        }
    } else {
        if (this.favoriteButton.getAlpha() == 0) {
            fadeAnimation = new AlphaAnimation(0, 1);
        } else {
            fadeAnimation = new AlphaAnimation(1, 1);
        }
    }

    fadeAnimation.setDuration(300);
    fadeAnimation.setFillAfter(true);

    this.favoriteButton.startAnimation(fadeAnimation);
    this.favoriteButton.setVisibility(View.VISIBLE);
}
Run Code Online (Sandbox Code Playgroud)
<ImageButton
        android:id="@+id/favoriteButton"
        android:src="@drawable/favorite_icon"
        android:background="@android:color/transparent"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="30dp"
        android:layout_marginBottom="20dp"
        android:visibility="invisible"
        android:onClick="didTapNotFavorite"
        />
Run Code Online (Sandbox Code Playgroud)

笔记:

由于这篇文章中的答案,我正在设置视图可见性,以使AlphaAnimation正常工作。

android android-animation

3
推荐指数
1
解决办法
1217
查看次数