【问题标题】:Understanding resize of a UIView with subview(UICollectionView) in landscape mode了解在横向模式下使用子视图(UICollectionView)调整 UIView 的大小
【发布时间】:2016-02-22 07:59:57
【问题描述】:

“我的视图” 有一个子视图 (UICollectionView)。子视图大小为纵向模式 0,0,375,50。

当我启动应用程序时。结果如下。

横向模式下的窗口大小为 0,0,375,667。

“我的视图”在横向模式下调整大小,子视图也调整大小。但是子视图大小还是0,0,375,50。

我期待 subview.bounds 返回 0,0,667,50。

以下答案说使用 bounds ,但对我来说它不起作用。查看调整大小但边界不正确。

Reporting incorrect bounds in landscape Mode

【问题讨论】:

    标签: ios objective-c uiview


    【解决方案1】:

    修复约束并感谢this answer by Followben,您可以根据您的视图方向重新计算并将其除以您的数组计数

    - (CGSize)collectionView:(UICollectionView *)collectionView
                      layout:(UICollectionViewLayout *)collectionViewLayout
      sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {    
        // Adjust cell size for orientation
        if (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
            return CGSizeMake(170.f, 170.f); //Make sure you calculate This
        }
        return CGSizeMake(192.f, 192.f); //Make sure you calculate This
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        [self.collectionView performBatchUpdates:nil completion:nil];
    }
    

    【讨论】:

    • 伟大的一个,难以捕捉和容易解决。方向改变时需要更新布局
    • 是的,很高兴我们一起解决了这个问题。如果您有任何问题,请始终在聊天室中联系我,如果可以,我会提供帮助。干杯!
    猜你喜欢
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 2013-04-12
    • 2011-07-17
    • 1970-01-01
    • 2012-08-28
    • 2013-06-09
    相关资源
    最近更新 更多