Im tạo ngang UICollectionView
và bên trong UICollectionViewCell
tôi có scrollview và bên trong scrollview tôi có một imageView.Xử lý kích thước cuộn trong UICollectionViewCell
Vấn đề tôi gặp phải là khi tôi phóng to hình ảnhXem, scrollView đang lấy tất cả kích thước ô, vì vậy nó không phù hợp với chiều cao và chiều rộng của kích thước hình ảnh. Bằng cách cuộn lên và xuống hình ảnh biến mất khỏi scrollview, tôi không có ý tưởng whats sai trong mã của tôi.
ColectionViewCell
Mã của tôi:
class CollectionViewCell: UICollectionViewCell {
@IBOutlet var scrollView: UIScrollView!
@IBOutlet var ImageV: UIImageView!
}
đang CollectionView:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
cell.scrollView.contentMode = UIViewContentMode.ScaleAspectFit
cell.scrollView.delegate = self
cell.ImageV.image = UIImage(named: array[indexPath.row])
cell.ImageV.contentMode = UIViewContentMode.ScaleAspectFit
cell.scrollView.minimumZoomScale = 1
cell.scrollView.maximumZoomScale = 4;
cell.scrollView.contentSize = cell.ImageV.frame.size
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: self.collectionView.frame.size.width , height: self.collectionView.frame.size.height - 100)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
let indexPath = NSIndexPath(forItem: Int(currentIndex), inSection: 0)
if let cell1 = self.collectionView.cellForItemAtIndexPath(indexPath) {
let cell = cell1 as! CollectionViewCell
let boundsSize = cell.scrollView.bounds.size
var contentsFrame = cell.ImageV.frame
if contentsFrame.size.width < boundsSize.width{
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width)/2
}else{
contentsFrame.origin.x = 0
}
if contentsFrame.size.height < boundsSize.height {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height)/2
}else{
contentsFrame.origin.y = 0
}
return cell.ImageV
}
return UIView()
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
currentIndex = self.collectionView.contentOffset.x/self.collectionView.frame.size.width;
oldcell = currentIndex - 1
let indexPath = NSIndexPath(forItem: Int(oldcell), inSection: 0)
if let cell1 = self.collectionView.cellForItemAtIndexPath(indexPath) {
let cell = cell1 as! CollectionViewCell
cell.scrollView.zoomScale = 0
}
}
hình ảnh xem trước: https://i.imgur.com/Gr2p09A.gifv
Dự án của tôi được tìm thấy ở đây:https://drive.google.com/file/d/0B32ROW7V8Fj4RVZfVGliXzJseGM/view?usp=sharing
Hey Tải xuống bản trình diễn và cho tôi biết tiền phạt của nó hay không sau khi tôi sẽ cập nhật câu trả lời của mình https://www.dropbox.com/s/i815mu0z4d0d76v/horizntal%203.zip?dl=0 –
Chắc chắn kiểm tra và cho biết me :) –
@RushangPrajapati, thuộc tính cuộn ScrollView nên được kích hoạt, trong trường hợp của bạn bị vô hiệu hóa vì vậy tôi có thể phóng to ra mà không cần cuộn để xem các giới hạn của hình ảnh hoặc phần còn lại của nó. bất kỳ giải pháp có thể? –