我创建了以下rightBarButtonItem
动画心形图标。它在模拟器设备,Iphone SE,8-plus,X上显示。但是当我连接到我的iPhone5物理设备时,它根本没有显示。
rightBarButtonItem
fav图标
在iPhone 5物理设备上,它已丢失,但带有后退按钮的leftBarButtonItem在所有设备上均正常。
我已尝试过代码的选项1和选项2但仍然相同,在物理设备iPhone5上缺失
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIButton *heart = [UIButton buttonWithType:UIButtonTypeCustom];
if ([sURL rangeOfString:@"true"].length > 0){
[heart setImage:[UIImage imageNamed:@"favorite30px.png"] forState:UIControlStateNormal];
}else{
[heart setImage:[UIImage imageNamed:@"notFavorite30px.png"] forState:UIControlStateNormal];
}
[heart addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
heart.imageEdgeInsets = UIEdgeInsetsMake(11.0, 0.0, -11.0, 0.0);
//--- Option 1
UIBarButtonItem *jobsButton = [[UIBarButtonItem alloc] initWithCustomView:heart];
self.navigationItem.rightBarButtonItem = jobsButton;
//--- Option 2
// self.btnFav = [[UIBarButtonItem alloc] initWithCustomView:heart];
// self.navigationItem.rightBarButtonItem = self.btnFav;
}
-(void)buttonTapped:(UIButton*)heart{
if( [[heart imageForState:UIControlStateNormal] isEqual:[UIImage imageNamed:@"notFavorite30px.png"]]) {
[heart setImage:[UIImage imageNamed:@"favorite30px.png"] forState:UIControlStateNormal];
[UIView animateKeyframesWithDuration:0.5
delay:0.0
options:0.0
animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.10 animations:^{
heart.transform = CGAffineTransformMakeScale(1.3, 1.3);
}];
[UIView addKeyframeWithRelativeStartTime:0.15 relativeDuration:0.25 animations:^{
heart.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
} completion:nil];
} else {
[heart setImage:[UIImage imageNamed:@"notFavorite30px.png"] forState:UIControlStateNormal];
[UIView animateKeyframesWithDuration:0.5
delay:0.0
options:0.0
animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.10 animations:^{
heart.transform = CGAffineTransformMakeScale(1.3, 1.3);
}];
[UIView addKeyframeWithRelativeStartTime:0.15 relativeDuration:0.25 animations:^{
heart.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
} completion:nil];
}
}