导航栏按钮动画出错

时间:2013-01-05 20:07:04

标签: ios uinavigationcontroller uiimageview uibarbuttonitem uinavigationitem

以下尝试制作导航按钮并为其设置动画,但我想我错过了一些东西。

请让我知道我哪里出错了。

谢谢! 这是一个自定义的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 个答案:

答案 0 :(得分:0)

想通了:

-(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];


}