0
我有兩個對象,第一個是ImageView,第二個是TextView。swift 3和UIImageview case
我爲這些對象做了動畫。如果用戶點擊圖像,textView將展開以顯示整個文本。但是,當textView展開時,imageView會顯示圖像的奇怪大小。它看起來像超級放大。
,這裏是我的代碼
import UIKit
類CollectionViewController:UICollectionViewController {
var imageViewArray = [UIImage]()
var textArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imageViewArray = [#imageLiteral(resourceName: "a"),#imageLiteral(resourceName: "b"),#imageLiteral(resourceName: "c")]
textArray = [
// firststory Starts
"firststory",
// SecondStory starts
"Hello",
// thirdStors starts
"thirdStory"]
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageViewArray.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as UICollectionViewCell
// give the objects their IDs
let imageView = cell.viewWithTag(1) as! UIImageView
imageView.image = imageViewArray[indexPath.row]
let textView = cell.viewWithTag(2) as! UITextView
textView.isScrollEnabled = false
textView.text = textArray[indexPath.row]
let backButton = cell.viewWithTag(3) as! UIButton
backButton.isHidden = true
return cell
}
// adding some animation to the cells
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath)
cell?.superview?.bringSubview(toFront: cell!)
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: [], animations: ({
cell?.frame = collectionView.bounds
collectionView.isScrollEnabled = false
let textView = cell!.viewWithTag(2) as! UITextView
textView.isScrollEnabled = false
// some codes to help back button to work !
let backButton = cell!.viewWithTag(3) as! UIButton
backButton.isHidden = false
backButton.addTarget(self, action: #selector(CollectionViewController.backbtnAction), for: UIControlEvents.touchUpInside)
}), completion: nil)
}
// back button
func backbtnAction() {
let indexPath = collectionView?.indexPathsForSelectedItems
collectionView?.isScrollEnabled = true
collectionView?.reloadItems(at: indexPath!)
}
}
你的問題是什麼?目前還不清楚你想達到什麼目標。 – Jurasic