Example One Example 2 hierarchy 当我按下按钮时,无法使用所需的UIView进行转录。通常是下一个UIView。 我需要进行转换才能使用按钮上方的UIView。
我正在使用此框架https://cocoapods.org/pods/MSPeekCollectionViewDelegateImplementation
我做错了什么?
import UIKit
import MSPeekCollectionViewDelegateImplementation
class ViewController: UIViewController {
var frontalView : UIView?
var dorsalView : UIView?
var fromView : UIView?
var toView : UIView?
let dorsalText = ["Hello" , "Friend" , "Goodbye" , "Time"]
let frontalText = ["Bilbo" , "Johny" , "Goodnight" , "to study"]
var flippedCard = false
@IBOutlet weak var cardsCollection: UICollectionView!
let delegate = MSPeekCollectionViewDelegateImplementation()
override func viewDidLoad() {
super.viewDidLoad()
cardsCollection.configureForPeekingDelegate()
cardsCollection.delegate = delegate
cardsCollection.dataSource = self
}
@IBAction func reverseButton(_ sender: Any) {
if flippedCard == true {
flippedCard = false
} else {
flippedCard = true
}
if flippedCard == true {
fromView = frontalView
toView = dorsalView
} else {
fromView = dorsalView
toView = frontalView
}
UIView.transition(from: fromView!, to: toView!, duration: 0.5, options: [.transitionFlipFromRight , .showHideTransitionViews])
}
}
extension ViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
let frontalViewCell = cell.viewWithTag(1) as! UIView
let frontalLabel = cell.viewWithTag(2) as! UILabel
let dorsalViewCell = cell.viewWithTag(3) as! UIView
let dorsalLabel = cell.viewWithTag(4) as! UILabel
frontalView = frontalViewCell
dorsalView = dorsalViewCell
frontalLabel.text = frontalText[indexPath.item]
dorsalLabel.text = dorsalText[indexPath.item]
cell.contentView.backgroundColor = UIColor.red
return cell
}
}
非常感谢您的帮助。