1

我有一个为 iOS 7 开发的餐厅菜单 iPad 应用程序,它使用collectionView在横向模式下水平滚动。菜单部分标题如下所示:

在此处输入图像描述

这就是节标题视图的 xib 文件的样子:

在此处输入图像描述

我知道它看起来很奇怪,因为标签是水平的,但我正在旋转标签,因此标签的文本从下到上垂直。

//Rotate the sectionHeader label
[sectionHeader.headerLabel setTransform:CGAffineTransformMakeRotation(-M_PI/2)];

现在的问题是,在更新到 iOS9 后,标签根本不会显示在部分标题视图中:

在此处输入图像描述

这是我的部分标题代码:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    //UICollectionReusableView *reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];

    SectionHeader *sectionHeader = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyHeaderID" forIndexPath:indexPath];



    //Load the Menu Sections from the menuSections Array
    MenuSection *menuSection = [[MenuSection alloc] init];
    menuSection = [self.menuSections objectAtIndex:indexPath.section];

    //Rotate the sectionHeader label
    [sectionHeader.headerLabel setTransform:CGAffineTransformMakeRotation(-M_PI/2)];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LanguageArabic"] == NO)
    {
        sectionHeader.headerLabel.text = [NSString stringWithFormat:@"%@", menuSection.sectionName];
    }
    else
    {
        sectionHeader.headerLabel.text = [NSString stringWithFormat:@"%@", menuSection.sectionNameArabic];
    }

    return sectionHeader;
}

当我在上面注释“旋转节标题”行并将 xib 文件中的标签固定为垂直并匹配节标题视图的大小时,我得到以下问题,因为标签的文本应该从下到上垂直读取像第一个屏幕截图:

在此处输入图像描述

最后,我使用 Todd Laney 的stickyHeaderFlowLayout 使节标题具有粘性。

为什么iOS9会发生这种情况,我该如何解决?谢谢

4

1 回答 1

3

当您应用旋转变换时,它会围绕其中心点旋转视图。您需要做的是在您的 xib 文件中设置标签的约束,以将其垂直和水平固定到超级视图的中心。然后当然你仍然在你的代码中应用旋转变换。那应该可以解决问题。

在此处输入图像描述

于 2016-05-24T16:53:37.903 回答