nicklockwood / iCarousel

A simple, highly customisable, data-driven 3D carousel for iOS and Mac OS
http://www.charcoaldesign.co.uk/source/cocoa#icarousel
Other
12k stars 2.58k forks source link

button(subview) to preform segue NOT working #844

Open Samc1007 opened 6 years ago

Samc1007 commented 6 years ago

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!

2018-01-23 2 12 42
314703405 commented 6 years ago

@Samc1007 I also got this problem.Do you have any idea about it?

salvasp commented 6 years ago

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

Samc1007 commented 6 years ago

@314703405 I'm sorry, no. I used collection View instead in the end, hope the solution above will help.

Samc1007 commented 6 years ago

@salvasp thanks for reply, i will try it out when i get back to it!