【问题标题】:UICollectionView Section Header view doesn't rotate properly in iOS9UICollectionView 部分标题视图在 iOS9 中无法正确旋转
【发布时间】:2016-09-19 11:47:24
【问题描述】:

我有一个为 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 会出现这种情况,我该如何解决? 谢谢

【问题讨论】:

    标签: objective-c ios7 uicollectionview ios9 sectionheader


    【解决方案1】:

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

    【讨论】:

    • 谢谢。那解决了它。解决方案是有道理的。虽然我仍然不知道它在 iOS 7 下如何运行良好。
    猜你喜欢
    • 2015-12-20
    • 2011-10-21
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多