uinavbar添加按钮动画问题

时间:2014-08-24 00:25:47

标签: ios objective-c iphone ios7 core-animation

目前我正在尝试向UINavigationBar添加按钮。这是我的代码:

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationOptionTransitionCurlDown
                 animations:^{
                     self.navigationItem.rightBarButtonItems =[NSArray arrayWithObject:[self.navigationItem.rightBarButtonItems objectAtIndex:0]];
                     searchBar.hidden= NO;
                     searchBar.bounds= CGRectMake(CGRectGetMidX(searchBar.bounds), CGRectGetMidY(searchBar.bounds), CGRectGetWidth(searchBar.bounds)+50, CGRectGetHeight(searchBar.bounds));
}
                 completion:nil
 ];

问题是无论我为动画设置了什么选项,RightBarButtonItem最终都被动画为"从左到右飞行"。 相反,我希望有一个淡入或类似的动画,看着它从左边飞到它右边的位置只是丑陋。

1 个答案:

答案 0 :(得分:1)

我试图成功,

-(void)viewDidAppear:(BOOL)animated{

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"Hi" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button sizeToFit];

[UIView transitionWithView:button
                  duration:2.0
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{
                    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

                } completion:^(BOOL finished) {

 }];

}

您可以尝试更多代码来正确使用它。你可以试试CATransition。 玩下面的代码,并告诉我你何时获得成功。祝你好运。