导航栏按钮动画错误

Posted

技术标签:

【中文标题】导航栏按钮动画错误【英文标题】:error with navigation bar button animation 【发布时间】:2013-01-05 20:07:04 【问题描述】:

以下尝试制作导航按钮并为其设置动画,但我认为我缺少一些东西。

请告诉我哪里出错了。

谢谢! 这是在自定义 UINavigationItem 类中

-(void)awakeFromNib
    [super awakeFromNib];
    UIImage *myimage = [UIImage imageNamed:@"navBarFilter.png"];
    NSArray * imageArray  = [[NSArray alloc] initWithObjects:
                             [UIImage imageNamed:@"navBarFilter.png"],
                             [UIImage imageNamed:@"navBarFilter1.png"],
                             [UIImage imageNamed:@"navBarFilter2.png"],
                             [UIImage imageNamed:@"navBarFilter3.png"],
                             [UIImage imageNamed:@"navBarFilter4.png"],
                             [UIImage imageNamed:@"navBarFilter5.png"],
                             nil];

    CGRect frameimg = CGRectMake(0, 0, myimage.size.width, myimage.size.height);

    UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
    [someButton setBackgroundImage:myimage forState:UIControlStateNormal];

    UIBarButtonItem *filterButton =[[UIBarButtonItem alloc] initWithCustomView:someButton];

    someButton.imageView.animationImages =imageArray;
    someButton.imageView.animationDuration=2.0;
    someButton.imageView.contentMode=UIViewContentModeBottomLeft;

    [someButton.imageView startAnimating];

    self.rightBarButtonItem =filterButton;

【问题讨论】:

错误信息是什么? 【参考方案1】:

想通了:

-(void)awakeFromNib
    [super awakeFromNib];

    NSArray * imageArray  = [[NSArray alloc] initWithObjects:
                             [UIImage imageNamed:@"navBarFilter.png"],
                         [UIImage imageNamed:@"navBarFilter1.png"],
                         [UIImage imageNamed:@"navBarFilter2.png"],
                         [UIImage imageNamed:@"navBarFilter3.png"],
                         [UIImage imageNamed:@"navBarFilter4.png"],
                         [UIImage imageNamed:@"navBarFilter5.png"],
                         nil];
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"navBarFilter.png"]];

    imageView.animationImages =imageArray;
    imageView.animationDuration=1.5;

    UIButton *someButton = [UIButton buttonWithType:UIButtonTypeCustom];
    someButton.bounds=imageView.bounds;
    [someButton addSubview:imageView];

    UIBarButtonItem *filterButton =[[UIBarButtonItem alloc] initWithCustomView:someButton];


    self.rightBarButtonItem =filterButton;
    [imageView startAnimating];



【讨论】:

以上是关于导航栏按钮动画错误的主要内容,如果未能解决你的问题,请参考以下文章

关闭 Twitter Bootstrap 导航栏转换动画

导航栏高度和自定义按钮

带有大标题的导航栏上的动画segue错误

导航栏中的iOS UIButton在执行变换动画后消失

带有透明导航栏的可见按钮

如何在 UINavigationBar 上添加 UISearchBar 动画