Skip to content

Commit cb84654

Browse files
committed
v0.2.1: Improvements for longPress position & Fix collectionView Reuse caused bugs
1 parent 3723b6e commit cb84654

15 files changed

Lines changed: 262 additions & 77 deletions

File tree

Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
8E9A7DF520969919009AEB6E /* LongPressWeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */; };
3232
8E9AE75B20773F3500B7004E /* ExampleOptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9AE75A20773F3500B7004E /* ExampleOptionsViewController.swift */; };
3333
8EBD62EA2096F8AD00520E58 /* LongPressViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */; };
34+
8EC8A46B209999A2002C7634 /* LongPressEventCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EC8A469209999A2002C7634 /* LongPressEventCell.swift */; };
35+
8EC8A46C209999A2002C7634 /* LongPressEventCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8EC8A46A209999A2002C7634 /* LongPressEventCell.xib */; };
3436
8EE28FBF20882DE900C69A77 /* JZCalendarWeekView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE28FBB20882D7A00C69A77 /* JZCalendarWeekView.framework */; };
3537
8EE28FC020882DE900C69A77 /* JZCalendarWeekView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE28FBB20882D7A00C69A77 /* JZCalendarWeekView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3638
/* End PBXBuildFile section */
@@ -100,6 +102,8 @@
100102
8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressWeekView.swift; sourceTree = "<group>"; };
101103
8E9AE75A20773F3500B7004E /* ExampleOptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleOptionsViewController.swift; sourceTree = "<group>"; };
102104
8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressViewController.swift; sourceTree = "<group>"; };
105+
8EC8A469209999A2002C7634 /* LongPressEventCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressEventCell.swift; sourceTree = "<group>"; };
106+
8EC8A46A209999A2002C7634 /* LongPressEventCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LongPressEventCell.xib; sourceTree = "<group>"; };
103107
8EE28FB520882D7900C69A77 /* JZCalendarWeekView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JZCalendarWeekView.xcodeproj; path = ../JZCalendarWeekView.xcodeproj; sourceTree = "<group>"; };
104108
/* End PBXFileReference section */
105109

@@ -216,6 +220,8 @@
216220
children = (
217221
8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */,
218222
8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */,
223+
8EC8A469209999A2002C7634 /* LongPressEventCell.swift */,
224+
8EC8A46A209999A2002C7634 /* LongPressEventCell.xib */,
219225
);
220226
path = LongPressViews;
221227
sourceTree = "<group>";
@@ -313,6 +319,7 @@
313319
isa = PBXResourcesBuildPhase;
314320
buildActionMask = 2147483647;
315321
files = (
322+
8EC8A46C209999A2002C7634 /* LongPressEventCell.xib in Resources */,
316323
8E5BB3DC2072F4A000FA853F /* LaunchScreen.storyboard in Resources */,
317324
8E5EE63D20857A6500150FD3 /* ExpandableHeaderView.xib in Resources */,
318325
8E7263E02074B55300ECF7CD /* EventCell.xib in Resources */,
@@ -335,6 +342,7 @@
335342
8E2E6567208D5F3600FB2CE4 /* BlackGridLine.swift in Sources */,
336343
8E5BB404207322BA00FA853F /* Event.swift in Sources */,
337344
8EBD62EA2096F8AD00520E58 /* LongPressViewController.swift in Sources */,
345+
8EC8A46B209999A2002C7634 /* LongPressEventCell.swift in Sources */,
338346
8E048ED9207F26F500A532BA /* OptionsTableViewCell.swift in Sources */,
339347
8E9A7DF520969919009AEB6E /* LongPressWeekView.swift in Sources */,
340348
8E7263DF2074B55300ECF7CD /* EventCell.swift in Sources */,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// LongPressEventCell.swift
3+
// JZCalendarWeekViewExample
4+
//
5+
// Created by Jeff Zhang on 2/5/18.
6+
// Copyright © 2018 Jeff Zhang. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import JZCalendarWeekView
11+
12+
class LongPressEventCell: JZBaseEventCell {
13+
14+
@IBOutlet weak var titleLabel: UILabel!
15+
@IBOutlet weak var locationLabel: UILabel!
16+
@IBOutlet weak var borderView: UIView!
17+
18+
override func awakeFromNib() {
19+
super.awakeFromNib()
20+
21+
setupBasic()
22+
}
23+
24+
func setupBasic() {
25+
self.clipsToBounds = true
26+
layer.shadowColor = UIColor.black.cgColor
27+
layer.shadowOffset = CGSize(width: 0, height: 4)
28+
layer.shadowRadius = 5
29+
layer.shadowOpacity = 0
30+
locationLabel.font = UIFont.systemFont(ofSize: 12)
31+
titleLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
32+
self.backgroundColor = UIColor(hex: 0xEEF7FF)
33+
borderView.backgroundColor = UIColor(hex: 0x0899FF)
34+
}
35+
36+
func updateView(event: Event) {
37+
self.event = event
38+
locationLabel.text = event.location
39+
titleLabel.text = event.title
40+
}
41+
42+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
6+
<dependencies>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
9+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
11+
</dependencies>
12+
<objects>
13+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
14+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
15+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="25R-T5-CF5" customClass="LongPressEventCell" customModule="JZCalendarWeekViewExample" customModuleProvider="target">
16+
<rect key="frame" x="0.0" y="0.0" width="220" height="123"/>
17+
<autoresizingMask key="autoresizingMask"/>
18+
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
19+
<rect key="frame" x="0.0" y="0.0" width="220" height="123"/>
20+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
21+
<subviews>
22+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="characterWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TU0-NI-510">
23+
<rect key="frame" x="5" y="5" width="212" height="17"/>
24+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
25+
<nil key="textColor"/>
26+
<nil key="highlightedColor"/>
27+
</label>
28+
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ic2-yw-Fo7">
29+
<rect key="frame" x="0.0" y="0.0" width="2" height="123"/>
30+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
31+
<constraints>
32+
<constraint firstAttribute="width" constant="2" id="ZHE-bM-NrH"/>
33+
</constraints>
34+
</view>
35+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hd0-ZR-rTQ">
36+
<rect key="frame" x="5" y="24" width="212" height="0.0"/>
37+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
38+
<nil key="textColor"/>
39+
<nil key="highlightedColor"/>
40+
</label>
41+
</subviews>
42+
</view>
43+
<constraints>
44+
<constraint firstItem="hd0-ZR-rTQ" firstAttribute="trailing" secondItem="TU0-NI-510" secondAttribute="trailing" id="DEE-Tn-36V"/>
45+
<constraint firstItem="Ic2-yw-Fo7" firstAttribute="top" secondItem="25R-T5-CF5" secondAttribute="top" id="MzP-zF-rJ0"/>
46+
<constraint firstItem="Ic2-yw-Fo7" firstAttribute="leading" secondItem="25R-T5-CF5" secondAttribute="leading" id="UbL-hJ-Ahd"/>
47+
<constraint firstItem="hd0-ZR-rTQ" firstAttribute="top" secondItem="TU0-NI-510" secondAttribute="bottom" constant="2" id="dfK-9u-IE5"/>
48+
<constraint firstAttribute="trailing" secondItem="TU0-NI-510" secondAttribute="trailing" constant="3" id="lMm-vv-ldl"/>
49+
<constraint firstItem="TU0-NI-510" firstAttribute="leading" secondItem="25R-T5-CF5" secondAttribute="leading" constant="5" id="lTX-m5-GGw"/>
50+
<constraint firstItem="TU0-NI-510" firstAttribute="top" secondItem="25R-T5-CF5" secondAttribute="top" constant="5" id="rlA-Yf-5Ef"/>
51+
<constraint firstItem="hd0-ZR-rTQ" firstAttribute="leading" secondItem="TU0-NI-510" secondAttribute="leading" id="vbe-EU-4eq"/>
52+
<constraint firstAttribute="bottom" secondItem="Ic2-yw-Fo7" secondAttribute="bottom" id="zhL-j8-GPY"/>
53+
</constraints>
54+
<viewLayoutGuide key="safeArea" id="hha-gv-ACH"/>
55+
<size key="customSize" width="220" height="123"/>
56+
<connections>
57+
<outlet property="borderView" destination="Ic2-yw-Fo7" id="XwY-SP-k9X"/>
58+
<outlet property="locationLabel" destination="hd0-ZR-rTQ" id="FAX-PA-bdS"/>
59+
<outlet property="titleLabel" destination="TU0-NI-510" id="0qh-cd-bPg"/>
60+
</connections>
61+
<point key="canvasLocation" x="85" y="76"/>
62+
</collectionViewCell>
63+
</objects>
64+
</document>

Example/JZCalendarWeekViewExample/Source/LongPressViews/LongPressViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ extension LongPressViewController: JZLongPressViewDelegate, JZLongPressViewDataS
9292
weekView.forceReload(reloadEvents: viewModel.eventsByDate)
9393
}
9494

95-
func weekView(_ weekView: JZLongPressWeekView, movingCell: UICollectionViewCell, didEndMoveLongPressAt startDate: Date) {
96-
let event = (movingCell as! EventCell).event!
95+
func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) {
96+
let event = editingEvent as! Event
9797
let duration = Calendar.current.dateComponents([.minute], from: event.startDate, to: event.endDate).minute!
9898
let selectedIndex = viewModel.events.index(where: { $0.id == event.id })!
9999
viewModel.events[selectedIndex].startDate = startDate

Example/JZCalendarWeekViewExample/Source/LongPressViews/LongPressWeekView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class LongPressWeekView: JZLongPressWeekView {
1414
override func registerViewClasses() {
1515
super.registerViewClasses()
1616

17-
self.collectionView.register(UINib(nibName: EventCell.className, bundle: nil), forCellWithReuseIdentifier: EventCell.className)
17+
self.collectionView.register(UINib(nibName: LongPressEventCell.className, bundle: nil), forCellWithReuseIdentifier: LongPressEventCell.className)
1818
}
1919

2020
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
21-
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: EventCell.className, for: indexPath) as! EventCell
21+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LongPressEventCell.className, for: indexPath) as! LongPressEventCell
2222
cell.updateView(event: getCurrentEvent(with: indexPath) as! Event)
2323
return cell
2424
}

Example/JZCalendarWeekViewExample/Source/RootViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RootViewModel: NSObject {
1818
lazy var events = [Event(id: "0", title: "One", startDate: firstDate, endDate: firstDate.add(component: .hour, value: 1), location: "Melbourne", eventType: 0),
1919
Event(id: "1", title: "Two", startDate: secondDate, endDate: secondDate.add(component: .hour, value: 4), location: "Sydney", eventType: 0),
2020
Event(id: "2", title: "Three", startDate: thirdDate, endDate: thirdDate.add(component: .hour, value: 2), location: "Tasmania", eventType: 1),
21-
Event(id: "3", title: "Four", startDate: thirdDate, endDate: thirdDate.add(component: .day, value: 2), location: "Canberra", eventType: 1)]
21+
Event(id: "3", title: "Four", startDate: thirdDate, endDate: thirdDate.add(component: .day, value: 1), location: "Canberra", eventType: 1)]
2222

2323
lazy var eventsByDate: EventsByDate = JZWeekViewHelper.getIntraEventsByDate(originalEvents: events)
2424

Example/JZCalendarWeekViewExample/Supporting Files/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.2.0</string>
18+
<string>0.2.1</string>
1919
<key>CFBundleVersion</key>
20-
<string>1805011500</string>
20+
<string>1805021706</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
2323
<key>UILaunchStoryboardName</key>

JZCalendarWeekView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "JZCalendarWeekView"
3-
s.version = "0.2.0"
3+
s.version = "0.2.1"
44
s.summary = "Calendar Week & Day View in iOS Swift"
55
s.homepage = "https://github.com/zjfjack/JZCalendarWeekView"
66
s.license = { :type => "MIT", :file => "LICENSE" }

JZCalendarWeekView.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
8E21E8AF20916A96002D72D0 /* JZLongPressWeekView.swift */,
120120
8E1BA95A206B4826007BE13C /* JZWeekViewFlowLayout.swift */,
121121
8E023C83206C732300C523BE /* JZBaseEvent.swift */,
122+
8E1BA971206B61B7007BE13C /* JZBaseEventCell.swift */,
122123
8E1BA969206B5350007BE13C /* JZWeekViewHelper.swift */,
123124
8E1BA95C206B4AD9007BE13C /* ReusableViews */,
124125
8E1BA955206B4687007BE13C /* Utils */,
@@ -140,7 +141,6 @@
140141
8E1BA95C206B4AD9007BE13C /* ReusableViews */ = {
141142
isa = PBXGroup;
142143
children = (
143-
8E1BA971206B61B7007BE13C /* JZBaseEventCell.swift */,
144144
8E1BA95F206B4B84007BE13C /* JZColumnHeader.swift */,
145145
8E1BA961206B4B99007BE13C /* JZRowHeader.swift */,
146146
8E1BA963206B4E82007BE13C /* JZCornerHeader.swift */,

JZCalendarWeekView/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.2.0</string>
18+
<string>0.2.1</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

0 commit comments

Comments
 (0)