UICollectionView在iPhone 6设备和iPhone 6模拟器上表现奇怪

时间:2014-11-23 13:56:15

标签: ios uiimageview uicollectionview ios-simulator iphone-6

我正在研究UICollectionView。我使用AVFoundation从iPhone相机拍摄照片。我将它们放在collectionView中。它在iPhone模拟器和原始设备上表现得很奇怪。

我在iPhone6模拟器上测试过它按预期工作但不在模拟器中。我只支持肖像模式。

其实我没有iPhone6设备。下面是客户端的截图。请看下面的内容,您将了解这些问题

  1. 图片显示的尺寸不同。
  2. 实际上应该连续排列5张图像
  3. 缺少最小项目间距
  4. 以下是我从模拟器中拍摄的图像

    以下是我从模拟器enter image description here

    中拍摄的图像

    我正在为layoutView使用不同的类。它有一个UIImageView和与该imageView相对应的代码

    class BLJobCollectionViewCell: UICollectionViewCell {
        let textLabel: UILabel!
        let imageView: UIImageView!
    
        override init(frame: CGRect) {
            super.init(frame: frame)
    
            imageView = UIImageView(frame: self.bounds)
            imageView.contentMode = UIViewContentMode.ScaleAspectFill
            self.contentView.addSubview(imageView)
            imageView.image = UIImage(named: "placeholder.png")
            self.imageView.clipsToBounds = true
        }
    .....
    }
    

    collectionView和flow-layout的代码

    var flowLayout = BLCollectionViewStickyheaderFlowLayout()
        //flowLayout.itemSize = CGSizeMake(78, 78)
        flowLayout.scrollDirection = UICollectionViewScrollDirection.Vertical
        flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0 , bottom: 0, right: 0)
        flowLayout.headerReferenceSize = CGSizeMake(50, 50)
        flowLayout.minimumInteritemSpacing = 2
        flowLayout.minimumLineSpacing = 2
        self.collectionView = UICollectionView(frame: CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height-50), collectionViewLayout: flowLayout)
    
    
    
        self.collectionView.collectionViewLayout = flowLayout
        self.collectionView.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(self.collectionView)
        self.collectionView.backgroundColor = UIColor.clearColor()
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        self.collectionView.registerClass(BLJobCollectionViewCell.self, forCellWithReuseIdentifier: "PhotoCell")
        self.collectionView.registerClass(BLJobCollectionViewAddCell.self, forCellWithReuseIdentifier: "AddCell")
    
        self.collectionView.registerClass(BLJobHeaderCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header")
    

    布局尺寸代码

     func collectionView(collectionView: UICollectionView,
        layout collectionViewLayout: UICollectionViewLayout,
        sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
    
            if( UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone && UIScreen.mainScreen().bounds.height == 667){
                if (UIDeviceOrientationIsPortrait( UIDevice.currentDevice().orientation)){
                    return CGSizeMake(73,73)
                }
            }
            return CGSizeMake(78, 78)
    }
    

    我正在使用自动布局显示视图。我在iPod touch上运行应用程序正常运行。

    而我想知道为什么它表现得很奇怪。我错过了什么。请指导我正确的方向。

    任何帮助都应该受到赞赏。提前谢谢。

0 个答案:

没有答案