iOS11:UIBarButtonItem,自定义视图不会在旋转时调整大小

时间:2017-09-08 05:31:59

标签: iphone cocoa-touch uibarbuttonitem ios11

我有这个:

enter image description here

当我旋转时,图标完全没有了(他们不像在< 11中那样调整大小和重新定位):

enter image description here

这就是我实现代码的方式。我将UINavigationBarsUIBarButtonItem设置为自定义图片,如下所示:

- (void) loadNavigationBarButton:(UIBarButtonItem*)navigationBarButton withSpacerWidth:(CGFloat)spacerWidth barButtonDirection:(CGFloat)barButtonDirection
{
        NSArray* items = @[navigationBarButton];

        if (barButtonDirection == 0)
        {
            [self.navigationItem setLeftBarButtonItems:items animated:NO];
        }
        else
        {
            [self.navigationItem setRightBarButtonItems:items animated:NO];
        }
}

这就是我初始化其中一个UIBarButtonItems

的方法
- (void) loadDefaultRightButton
{
    ButtonView *rightButtonView = [[ButtonView alloc] initWithFrame:CGRectMake(0, 0, 60.71090047393365, 44) image:[[[NextButtonIcon alloc] initWithHighlight:NO] imageForSize:CGSizeMake(60.71090047393365, 44)] highlightFrame:CGRectMake(0, 0, 60.71090047393365, 44) highlightImage:[[[NextButtonIcon alloc] initWithHighlight:YES] imageForSize:CGSizeMake(60.71090047393365, 44)] highlightOnTop:YES buttonViewType:ButtonViewTypeNext roundedCorners:NO enableDisabledView: NO  doubleTap:NO singleTapGestureRecognizer:nil];
    rightButtonView.delegate = self;
    [rightButtonView.widthAnchor constraintEqualToConstant: 60.71090047393365].active = YES;
    [rightButtonView.heightAnchor constraintEqualToConstant: 44].active = YES;
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:rightButtonView];
    [self loadNavigationBarButton:rightButton withSpacerWidth:21 barButtonDirection:1];
}

由于某种原因,当我旋转到横向时,UIBarButtonItems不会像过去那样调整自己的大小。它们保持大而且溢出屏幕。有谁知道为什么会这样?我的UIViewControllers占据了全屏fwiw。

更新:添加了图片和其他澄清评论。

0 个答案:

没有答案