3

leftBarButtonItem から UISearchBar のサイズを変更するときに、簡単なアニメーションを追加しようとしています。何らかの理由で、サイズ変更はアニメーション化されませんが、searchBar のサイズは変更されます。ただし、searchBar のアルファを変更しようとすると、アニメーション化されます。

ここにコードがあります

UISearchBar *baseSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:baseSearchBar];

アニメーションの方法は次のとおりです。

  [UIView animateWithDuration:2.0f animations:^{
    searchBar.frame = CGRectMake(0, 0, 400, 40);
    searchBar.alpha = 0;
} completion:^(BOOL finished) {  
}];

私が言ったように、サイズ変更は機能しますが、アニメーション化されず、アルファを変更しようとするとアニメーションが機能します。

もう1つ... rightBarButtonItemに対して同じことを試みたところ、アニメーションが機能しました..

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
           action:@selector(expandWithAnimation:)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Test" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 50, 40);
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

前もって感謝します

4

0 に答える 0