 
 import UIKit
 
-public class TagView: UIView {
+public class TagView: UIView, UIScrollViewDelegate {
     
     public enum Align {
         case Center

    }
    
    public func deselectTagAtIndex(index:Int) {
        tagViews[index].selected = false        
    }
    
    func tapSelect (sender : UITapGestureRecognizer) {

        let numberOfTags = dataSource.numberOfTags(self)
        
        if numberOfTags == 0 {
            invalidateIntrinsicContentSize()
            return
        }
        
        func isNewPageRequired() -> Bool {
            let newRowCount = pages[currentPageIndex].count + 1
            let newPageHeight = (dataSource.heightOfTag(self) + self.cellInsets.top + cellInsets.bottom) * (CGFloat(newRowCount) )
            
            if let maxAllowedRows = self.maxAllowedRows where newRowCount > Int(maxAllowedRows) {
                //                        print("pageRows=\(pageRows) > maxAllowedRows=\(maxAllowedRows)")
                return true
            } else if let maxAllowedHeight = self.maxAllowedHeight where Float(newPageHeight) > maxAllowedHeight {
                return true
            } else {
                return false
            }
        }
        
        func addNewPage() {
            currentPageIndex++
            pages.append([])
            rowsWidth.append([])
            y = 0
        }
        
        for i in 0..<numberOfTags {
            print("processing cell at index=\(i)...")
            let cell = dataSource.tagCellForTagView(self, index: i)
            
            tagViews.append(cell)
