Skip to content

Commit

Permalink
Fix up Issue that UITableViews cells or UICollectionViews cell is n…
Browse files Browse the repository at this point in the history
…ot selected.

This is an issue that tapGesture of cell in collectionView or tapGesture of
cell in tableView  collides with tapGesture of mainContainerView.
  • Loading branch information
audrl1010 authored and Myung gi son committed Nov 7, 2017
1 parent b8fdd05 commit 75187c7
Show file tree
Hide file tree
Showing 2 changed files with 385 additions and 58 deletions.
227 changes: 227 additions & 0 deletions SlideMenuController/Classes/Base.swift
Original file line number Diff line number Diff line change
@@ -0,0 1,227 @@
//
// Base.swift
//
// Created by myung gi son on 2017. 11. 5..
//

import UIKit

// MARK: - CanBeSubview

/// This is a protocol that allow adding subviews
/// to the superview without distinction of CALayer or UIView.
public protocol CanBeSubview {}

extension UIView: CanBeSubview {}
extension CALayer: CanBeSubview {}

extension UIView {
public func addSubviews(_ subviews: UIView...) -> UIView {
subviews.forEach { addSubview($0) }
return self
}
}

extension CALayer {
public func addSublayers(_ sublayers: CALayer...) -> CALayer {
sublayers.forEach { addSublayer($0) }
return self
}
}

// MARK: - BaseViewController

open class BaseViewController: UIViewController {

open override func viewDidLoad() {
super.viewDidLoad()
configureSubviews(ofSuperview: view)
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// After configure propertys for each view,
/// return an array of views to add to the superview in desired order.
open func setupViews() -> [CanBeSubview]? {
return nil
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Configure the constraints for each view.
open func setupConstraints() {}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Execute `setupViews` method and
/// add an array of views desired order to the superview
/// and execute `setupConstraints` method.
public func configureSubviews(ofSuperview superview: UIView) {
setupViews()?.forEach {
if let subLayer = $0 as? CALayer {
superview.layer.addSublayer(subLayer)
}
else {
superview.addSubview($0 as! UIView)
}
}
setupConstraints()
}
}

// MARK: - BaseView

open class BaseView: UIView {

public override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}

private func commonInit() {
configureSubviews(ofSuperview: self)
}
// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// After configure propertys for each view,
/// return an array of views to add to the superview in desired order.
open func setupViews() -> [CanBeSubview]? {
return nil
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Configure the constraints for each view.
open func setupConstraints() {}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Execute `setupViews` method and
/// add an array of views desired order to the superview
/// and execute `setupConstraints` method.
public func configureSubviews(ofSuperview superview: UIView) {
setupViews()?.forEach {
if let subLayer = $0 as? CALayer {
superview.layer.addSublayer(subLayer)
}
else {
superview.addSubview($0 as! UIView)
}
}
setupConstraints()
}
}

// MARK: - BaseTableViewCell

open class BaseTableViewCell: UITableViewCell {

public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
commonInit()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}

private func commonInit() {
configureSubviews(ofSuperview: self)
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// After configure propertys for each view,
/// return an array of views to add to the superview in desired order.
open func setupViews() -> [CanBeSubview]? {
return nil
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Configure the constraints for each view.
open func setupConstraints() {}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Execute `setupViews` method and
/// add an array of views desired order to the superview
/// and execute `setupConstraints` method.
public func configureSubviews(ofSuperview superview: UIView) {
setupViews()?.forEach {
if let subLayer = $0 as? CALayer {
superview.layer.addSublayer(subLayer)
}
else {
superview.addSubview($0 as! UIView)
}
}
setupConstraints()
}
}

// MARK: - BaseCollectionViewCell

open class BaseCollectionViewCell: UICollectionViewCell {
public override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}

private func commonInit() {
configureSubviews(ofSuperview: self)
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// After configure propertys for each view,
/// return an array of views to add to the superview in desired order.
open func setupViews() -> [CanBeSubview]? {
return nil
}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Configure the constraints for each view.
open func setupConstraints() {}

// this is kind of ugly I know :(
// Swift compiler reports "Not supported yet" when trying to override protocol extensions

/// Execute `setupViews` method and
/// add an array of views desired order to the superview
/// and execute `setupConstraints` method.
public func configureSubviews(ofSuperview superview: UIView) {
setupViews()?.forEach {
if let subLayer = $0 as? CALayer {
superview.layer.addSublayer(subLayer)
}
else {
superview.addSubview($0 as! UIView)
}
}
setupConstraints()
}
}
Loading

0 comments on commit 75187c7

Please sign in to comment.