0

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

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

谢谢!这是在自定义 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;
}
4

1 回答 1

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


}
于 2013-01-05T20:55:34.740 回答