Open Samc1007 opened 6 years ago
@Samc1007 I also got this problem.Do you have any idea about it?
You can create a custom class for the carousel view (xib and CustomClass:UIView) with a button and the imageview then
func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
var cell: CustomClass
if view == nil {
cell = Bundle.main.loadNibNamed(String(describing: CustomClass.self), owner: self, options: nil)?.first as! CustomClass
cell.frame = CGRect(x: 0, y: 0, width: 225, height: 100) // carousel.frame
cell.autoresizingMask = [UIViewAutoresizing.flexibleLeftMargin, UIViewAutoresizing.flexibleRightMargin, UIViewAutoresizing.flexibleTopMargin, UIViewAutoresizing.flexibleBottomMargin]
cell.translatesAutoresizingMaskIntoConstraints = true
} else {
cell = view as! CustomClass
}
cell.albumView.image = Covers[index]
///other configuration but you cam move them in CustomClass awakeFromNib
cell.button.buttonDelegate = self //THIS
}
extension YourController: ButtonDelegate {
func tappedButton() {
//perform segue
}
}
class CustomClass: UIView {
@IBOutlet weak var theButton: UIButton!
// @IBOutlet imageview
var buttonDelegate: ButtonDelegate?
override func awakeFromNib() {
super.awakeFromNib()
//configure
}
@IBAction func buttonTapped(_ sender: UIButton) { // connect using Storyboard touchup inside
self.buttonDelegate?.tappedButton()
}
}
protocol ButtonDelegate {
func tappedButton()
//func anothertappedButton()
// func longtappedButton()
}
you can also try to bring the button to the front
@314703405 I'm sorry, no. I used collection View instead in the end, hope the solution above will help.
@salvasp thanks for reply, i will try it out when i get back to it!
Thanks for the awesome work! Yet I got a problem here, I was trying to trigger a segue to a new collection ViewController by subviewing UIButton, the code as follow. The code was built without any error and warning, but after tapping on the button(Carousel view), nothing happen. Could anyone help me out? Thanks in advance!