简体   繁体   English

了解横向模式下带有子视图(UICollectionView)的UIView的大小

[英]Understanding resize of a UIView with subview(UICollectionView) in landscape mode

在此处输入图片说明

"My View" has a subview ( UICollectionView ). “我的视图”具有一个子视图( UICollectionView )。 The subview size is portrait mode 0,0,375,50. 子视图的大小为纵向模式0,0,375,50。

When I launch the app. 当我启动应用程序时。 in landscape following are the results. 结果如下。

Window size in landscape mode is 0,0,375,667. 横向模式下的窗口大小为0,0,375,667。

"My View" resize's in landscape mode, subview also resize's. 横向模式下“我的视图”调整大小,子视图也调整大小。 But the subview size is still 0,0,375,50. 但是子视图的大小仍然是0,0,375,50。

I was expecting subview.bounds to return 0,0,667,50. 我期望subview.bounds返回0,0,667,50。

The following answer says use bounds , but for me its not working. 以下答案表示使用范围,但对我而言,它不起作用。 View resize's but bounds are incorrect. 查看调整大小,但范围不正确。

Reporting incorrect bounds in landscape Mode 在横向模式下报告错误边界

Fixing the constraint and Thank to this answer by Followben you can recalculate base on your view orientation and divide it by your array count 修正约束并感谢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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM