I am working on UICollectionView.I took pictures from iPhone camera using AVFoundation.And i place them in the collectionView. Its behaving strangely on iPhone simulator and original device.
I tested this on iPhone6 simulator its working as expected but not in simulator. and i am supporting only portrait mode.
Actually i don't have iPhone6 device.below are the screenshots from the client. Please look at the below you will get understand the problem those are
- Images were showing different sizes.
- Actually there should 5 images aligned in a row
- Minimum item interspacing is missing
Below is the image i have taken from simulator
Below is the image i have taken from simulator
I am using a different class for layoutView. it has a UIImageView and code corresponding to that 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
}
.....
}
code for collectionView and 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")
code for layout size
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)
}
And i am using auto-layout for views displaying. And i run the app on iPod touch its working fine as expected.
And what i want to know why its behaving strangely. Am i missed something . please guide me in proper direction.
And any help should be appreciated. Thanks in advance.