rightBarButtonItem显示在所有模拟器上但未在物理iPhone5设备上显示

时间:2018-03-14 09:08:49

标签: ios objective-c uibutton ios-simulator uibarbuttonitem

我创建了以下rightBarButtonItem动画心形图标。它在模拟器设备,Iphone SE,8-plus,X上显示。但是当我连接到我的iPhone5物理设备时,它根本没有显示。

在模拟器iPhoneX上显示

rightBarButtonItem fav图标

pic

在iPhone 5物理设备上,它已丢失,但带有后退按钮的leftBarButtonItem在所有设备上均正常。

enter image description here

我已尝试过代码的选项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];
    }
}

Debug View Hierachy

iPhone 5s SIMULATOR,FAV图标显示在导航栏

iPhone5s Simulator

iPhone 5 DEVICE,导航栏中缺少FAV图标

enter image description here

0 个答案:

没有答案