如何在 Objective c 中使用动画导航栏按钮
How to use animated Navigation bar button in Objective c
我想在导航栏按钮上添加这张图片,如何在导航栏右栏按钮或左栏按钮上使用这张图片?
请检查下面的代码,我正在使用这些代码在导航栏按钮上查看与工作代码相同的代码:-
- (void)viewDidLoad
{
[super viewDidLoad];
// Animation
UIImageView*animationView = [[UIImageView alloc] initWithFrame:self.view.frame];
animationView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.gif"],
[UIImage imageNamed:@"2.gif"],
[UIImage imageNamed:@"3.gif"],
[UIImage imageNamed:@"4.gif"],
[UIImage imageNamed:@"5.gif"],
[UIImage imageNamed:@"6.gif"],nil];
animationView.animationDuration = 1.25;
animationView.animationRepeatCount = 0;
[animationView startAnimating];
[self.view addSubview:animationView];
}
让我知道怎么做
在导航栏按钮上使用此代码。
谢谢!
我试过你的代码,加上我的小技巧,效果很神奇。
NSArray *imageArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"tmp-0"],
[UIImage imageNamed:@"tmp-1"],
[UIImage imageNamed:@"tmp-2"],
[UIImage imageNamed:@"tmp-3"],
[UIImage imageNamed:@"tmp-4"],
[UIImage imageNamed:@"tmp-5"],
[UIImage imageNamed:@"tmp-6"],
[UIImage imageNamed:@"tmp-7"],nil];
UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
[barButton setImage:[UIImage imageNamed:@"tmp-0"] forState:UIControlStateNormal]; // mine trick
[barButton.imageView setAnimationImages:imageArray];
[barButton.imageView setAnimationDuration:1.0f];
[barButton.imageView startAnimating];
[barButton sizeToFit];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
你需要先给barButton一个图片,这样你的按钮才能做成frame
我想在导航栏按钮上添加这张图片,如何在导航栏右栏按钮或左栏按钮上使用这张图片?
请检查下面的代码,我正在使用这些代码在导航栏按钮上查看与工作代码相同的代码:-
- (void)viewDidLoad
{
[super viewDidLoad];
// Animation
UIImageView*animationView = [[UIImageView alloc] initWithFrame:self.view.frame];
animationView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.gif"],
[UIImage imageNamed:@"2.gif"],
[UIImage imageNamed:@"3.gif"],
[UIImage imageNamed:@"4.gif"],
[UIImage imageNamed:@"5.gif"],
[UIImage imageNamed:@"6.gif"],nil];
animationView.animationDuration = 1.25;
animationView.animationRepeatCount = 0;
[animationView startAnimating];
[self.view addSubview:animationView];
}
让我知道怎么做 在导航栏按钮上使用此代码。
谢谢!
我试过你的代码,加上我的小技巧,效果很神奇。
NSArray *imageArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"tmp-0"],
[UIImage imageNamed:@"tmp-1"],
[UIImage imageNamed:@"tmp-2"],
[UIImage imageNamed:@"tmp-3"],
[UIImage imageNamed:@"tmp-4"],
[UIImage imageNamed:@"tmp-5"],
[UIImage imageNamed:@"tmp-6"],
[UIImage imageNamed:@"tmp-7"],nil];
UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
[barButton setImage:[UIImage imageNamed:@"tmp-0"] forState:UIControlStateNormal]; // mine trick
[barButton.imageView setAnimationImages:imageArray];
[barButton.imageView setAnimationDuration:1.0f];
[barButton.imageView startAnimating];
[barButton sizeToFit];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
你需要先给barButton一个图片,这样你的按钮才能做成frame