Skip to content

Commit

Permalink
mixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazuhiro Hayashi committed Jul 17, 2017
1 parent c9614d4 commit 8aa9833
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
59 changes: 59 additions & 0 deletions PagingKit/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,63 @@ public class PagingMenuView: UIScrollView {
placeNewCellOnRight(with: minX, index: numberOfItem - 1, dataSource: dataSource)
}

if var lastCell = visibleCell.last {
var rightEdge = lastCell.frame.maxX
while rightEdge < maxX, (0..<numberOfItem) ~= lastCell.index + 1 {
rightEdge = placeNewCellOnRight(with: rightEdge, index: lastCell.index, dataSource: dataSource)
lastCell = visibleCell.last!
}
}

if var firstCell = visibleCell.first {
var leftEdge = firstCell.frame.minX
while leftEdge > minX, (0..<numberOfItem) ~= firstCell.index - 1 {
leftEdge = placeNewCellOnLeft(with: leftEdge, index: firstCell.index, dataSource: dataSource)
firstCell = visibleCell.first!
}
}

var lastCell = visibleCell.last!
while lastCell.frame.minX > maxX {
lastCell.removeFromSuperview()
let recycleCell = visibleCell.removeLast()

// enqueue
if let cells = queue[recycleCell.identifier] {
queue[recycleCell.identifier] = cells + [recycleCell]
} else {
queue[recycleCell.identifier] = [recycleCell]
}

lastCell = visibleCell.last!
}


var firstCell = visibleCell.first!
while firstCell.frame.maxX < minX {
firstCell.removeFromSuperview()
let recycleCell = visibleCell.removeFirst()

// enqueue
if let cells = queue[recycleCell.identifier] {
queue[recycleCell.identifier] = cells + [recycleCell]
} else {
queue[recycleCell.identifier] = [recycleCell]
}

firstCell = visibleCell.first!
}
}

private func tileCellInfinity(from minX: CGFloat, to maxX: CGFloat) {
guard let dataSource = dataSource else {
return
}

if visibleCell.isEmpty {
placeNewCellOnRight(with: minX, index: numberOfItem - 1, dataSource: dataSource)
}

if var lastCell = visibleCell.last {
var rightEdge = lastCell.frame.maxX
while rightEdge < maxX {
Expand Down Expand Up @@ -258,6 +315,8 @@ public class PagingMenuView: UIScrollView {
}
}



public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let selectedCell = touches.first.flatMap { $0.location(in: self) }.flatMap { hitTest($0, with: event) as? PagingMenuCell }
if let index = selectedCell?.index {
Expand Down
6 changes: 3 additions & 3 deletions iOS Sample/iOS Sample/MenuCell.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -15,7 +15,7 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="96"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9DC-uB-GDb">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="9DC-uB-GDb">
<rect key="frame" x="8" y="8" width="359" height="80"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand Down

0 comments on commit 8aa9833

Please sign in to comment.