내 thumbnailImage에 CollectionView 셀의 탭 제스처가 있습니다. 스토리 보드를 사용하지 않고 다른 View Controller에 푸시/프리젠 테이션/프레젠테이션을 할 때 작동했습니다. 이제 스토리 보드를 구현 했으므로 더 이상 작동하지 않으며 많은 다른 솔루션이며 전환이 없습니다. 스토리 보드에 클래스를 설정했지만 모든 것이 프로그래밍 방식으로 수행됩니다. 현재 ViewController에서 CollectionView 셀로 전환 할 수있는 방법이 있는지 궁금합니다. 스토리 보드의CollectionView Cell segue
그림 :
이것은 시뮬레이터의 모습입니다 :
이import UIKit
class Cell: UICollectionViewCell{
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
let tapRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(Tap(recognizer:)))
thumbnailImage.isUserInteractionEnabled = true
thumbnailImage.addGestureRecognizer(tapRecognizer)
}
func setupViews(){
addSubview(thumbnailImage)
addSubview(separatorView)
addSubview(brandName)
addSubview(Priceing)
addSubview(model)
addConstraintsWithFormat(format: "H:|-16-[v0]-16-|", views: thumbnailImage)
addConstraintsWithFormat(format: "H:|[v0]|", views: separatorView)
//Vertical Contsraint
addConstraintsWithFormat(format: "V:[v0(200)]-87-[v1(1)]|", views: thumbnailImage, separatorView)
addConstraintsWithFormat(format: "V:[v0(20)]", views: brandName)
addConstraintsWithFormat(format: "V:[v0(20)]", views: Priceing)
addConstraintsWithFormat(format: "V:[v0(20)]", views: model)
addConstraint(NSLayoutConstraint(item: brandName, attribute: .top, relatedBy: .equal, toItem: thumbnailImage, attribute: .bottom, multiplier: 1, constant: 8))
addConstraint(NSLayoutConstraint(item: brandName, attribute: .right, relatedBy: .equal, toItem: thumbnailImage, attribute: .right, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: brandName, attribute: .left, relatedBy: .equal, toItem: thumbnailImage, attribute: .left, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: Priceing, attribute: .top, relatedBy: .equal, toItem: brandName, attribute: .bottom, multiplier: 1, constant: 4))
addConstraint(NSLayoutConstraint(item: Priceing, attribute: .right, relatedBy: .equal, toItem: brandName, attribute: .right, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: Priceing, attribute: .left, relatedBy: .equal, toItem: brandName, attribute: .left, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: model, attribute: .top, relatedBy: .equal, toItem: Priceing, attribute: .bottom, multiplier: 1, constant: 4))
addConstraint(NSLayoutConstraint(item: model, attribute: .right, relatedBy: .equal, toItem: Priceing, attribute: .right, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: model, attribute: .left, relatedBy: .equal, toItem: Priceing, attribute: .left, multiplier: 1, constant: 0))
}
let separatorView: UIView = {
let view = UIView()
view.backgroundColor = UIColor(displayP3Red: 230/255, green: 230/255, blue: 230/255, alpha: 1)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let brandName: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.backgroundColor = UIColor.rgb(displayP3Red: 211, green: 211, blue: 211)
label.numberOfLines = 2
return label
}()
let model: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.backgroundColor = UIColor.rgb(displayP3Red: 211, green: 211, blue: 211)
label.numberOfLines = 1
return label
}()
let Priceing: UILabel = {
let textView = UILabel()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.numberOfLines = 1
textView.backgroundColor = UIColor.rgb(displayP3Red: 211, green: 211, blue: 211)
return textView
}()
let thumbnailImage: UIImageView = {
let image = UIImageView()
image.backgroundColor = UIColor.rgb(displayP3Red: 211, green: 211, blue: 211)
image.contentMode = .scaleAspectFill
image.clipsToBounds = true
return image
}()
@objc func Tap(recognizer: UITapGestureRecognizer){
let vc = DescriptionViewController()
// let nc = self.window?.rootViewController?.navigationController
// let transition = CATransition()
// transition.duration = 0.3
// transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
// transition.type = kCATransitionMoveIn
// transition.subtype = kCATransitionFromTop
// nc?.navigationController?.view.layer.add(transition, forKey: nil)
self.window?.rootViewController?.navigationController?.pushViewController(vc, animated: false)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
'UICollectionViewCell' 클래스를 사용하는 대신 네비게이션을 위해 UIViewController 클래스를 사용하십시오. –
@RichieRich 그 thumbnailImage에 대한 구체적인 제스처는 어떻게 UIViewController에서 할 수 있습니까? UIViewController에 탭 제스처가 있다면 UIViewController 클래스에 CollectionView와 UIButton 만 있기 때문에 어떻게 작동할까요? –
데모 프로젝트를 공유 할 수 있다면 도와 드리겠습니다. –