Skip to content

Commit

Permalink
v0.2.1: Improvements for longPress position & Fix collectionView Reus…
Browse files Browse the repository at this point in the history
…e caused bugs
  • Loading branch information
zjfjack committed May 2, 2018
1 parent 3723b6e commit cb84654
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 77 deletions.
8 changes: 8 additions & 0 deletions Example/JZCalendarWeekViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
8E9A7DF520969919009AEB6E /* LongPressWeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */; };
8E9AE75B20773F3500B7004E /* ExampleOptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E9AE75A20773F3500B7004E /* ExampleOptionsViewController.swift */; };
8EBD62EA2096F8AD00520E58 /* LongPressViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */; };
8EC8A46B209999A2002C7634 /* LongPressEventCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8EC8A469209999A2002C7634 /* LongPressEventCell.swift */; };
8EC8A46C209999A2002C7634 /* LongPressEventCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8EC8A46A209999A2002C7634 /* LongPressEventCell.xib */; };
8EE28FBF20882DE900C69A77 /* JZCalendarWeekView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE28FBB20882D7A00C69A77 /* JZCalendarWeekView.framework */; };
8EE28FC020882DE900C69A77 /* JZCalendarWeekView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8EE28FBB20882D7A00C69A77 /* JZCalendarWeekView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -100,6 +102,8 @@
8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressWeekView.swift; sourceTree = "<group>"; };
8E9AE75A20773F3500B7004E /* ExampleOptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleOptionsViewController.swift; sourceTree = "<group>"; };
8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressViewController.swift; sourceTree = "<group>"; };
8EC8A469209999A2002C7634 /* LongPressEventCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongPressEventCell.swift; sourceTree = "<group>"; };
8EC8A46A209999A2002C7634 /* LongPressEventCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LongPressEventCell.xib; sourceTree = "<group>"; };
8EE28FB520882D7900C69A77 /* JZCalendarWeekView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = JZCalendarWeekView.xcodeproj; path = ../JZCalendarWeekView.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -216,6 +220,8 @@
children = (
8EBD62E92096F8AD00520E58 /* LongPressViewController.swift */,
8E9A7DF420969919009AEB6E /* LongPressWeekView.swift */,
8EC8A469209999A2002C7634 /* LongPressEventCell.swift */,
8EC8A46A209999A2002C7634 /* LongPressEventCell.xib */,
);
path = LongPressViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -313,6 +319,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8EC8A46C209999A2002C7634 /* LongPressEventCell.xib in Resources */,
8E5BB3DC2072F4A000FA853F /* LaunchScreen.storyboard in Resources */,
8E5EE63D20857A6500150FD3 /* ExpandableHeaderView.xib in Resources */,
8E7263E02074B55300ECF7CD /* EventCell.xib in Resources */,
Expand All @@ -335,6 +342,7 @@
8E2E6567208D5F3600FB2CE4 /* BlackGridLine.swift in Sources */,
8E5BB404207322BA00FA853F /* Event.swift in Sources */,
8EBD62EA2096F8AD00520E58 /* LongPressViewController.swift in Sources */,
8EC8A46B209999A2002C7634 /* LongPressEventCell.swift in Sources */,
8E048ED9207F26F500A532BA /* OptionsTableViewCell.swift in Sources */,
8E9A7DF520969919009AEB6E /* LongPressWeekView.swift in Sources */,
8E7263DF2074B55300ECF7CD /* EventCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// LongPressEventCell.swift
// JZCalendarWeekViewExample
//
// Created by Jeff Zhang on 2/5/18.
// Copyright © 2018 Jeff Zhang. All rights reserved.
//

import UIKit
import JZCalendarWeekView

class LongPressEventCell: JZBaseEventCell {

@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var locationLabel: UILabel!
@IBOutlet weak var borderView: UIView!

override func awakeFromNib() {
super.awakeFromNib()

setupBasic()
}

func setupBasic() {
self.clipsToBounds = true
layer.shadowColor = UIColor.black.cgColor
layer.shadowOffset = CGSize(width: 0, height: 4)
layer.shadowRadius = 5
layer.shadowOpacity = 0
locationLabel.font = UIFont.systemFont(ofSize: 12)
titleLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
self.backgroundColor = UIColor(hex: 0xEEF7FF)
borderView.backgroundColor = UIColor(hex: 0x0899FF)
}

func updateView(event: Event) {
self.event = event
locationLabel.text = event.location
titleLabel.text = event.title
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="25R-T5-CF5" customClass="LongPressEventCell" customModule="JZCalendarWeekViewExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="220" height="123"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="220" height="123"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<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">
<rect key="frame" x="5" y="5" width="212" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Ic2-yw-Fo7">
<rect key="frame" x="0.0" y="0.0" width="2" height="123"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="2" id="ZHE-bM-NrH"/>
</constraints>
</view>
<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">
<rect key="frame" x="5" y="24" width="212" height="0.0"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</view>
<constraints>
<constraint firstItem="hd0-ZR-rTQ" firstAttribute="trailing" secondItem="TU0-NI-510" secondAttribute="trailing" id="DEE-Tn-36V"/>
<constraint firstItem="Ic2-yw-Fo7" firstAttribute="top" secondItem="25R-T5-CF5" secondAttribute="top" id="MzP-zF-rJ0"/>
<constraint firstItem="Ic2-yw-Fo7" firstAttribute="leading" secondItem="25R-T5-CF5" secondAttribute="leading" id="UbL-hJ-Ahd"/>
<constraint firstItem="hd0-ZR-rTQ" firstAttribute="top" secondItem="TU0-NI-510" secondAttribute="bottom" constant="2" id="dfK-9u-IE5"/>
<constraint firstAttribute="trailing" secondItem="TU0-NI-510" secondAttribute="trailing" constant="3" id="lMm-vv-ldl"/>
<constraint firstItem="TU0-NI-510" firstAttribute="leading" secondItem="25R-T5-CF5" secondAttribute="leading" constant="5" id="lTX-m5-GGw"/>
<constraint firstItem="TU0-NI-510" firstAttribute="top" secondItem="25R-T5-CF5" secondAttribute="top" constant="5" id="rlA-Yf-5Ef"/>
<constraint firstItem="hd0-ZR-rTQ" firstAttribute="leading" secondItem="TU0-NI-510" secondAttribute="leading" id="vbe-EU-4eq"/>
<constraint firstAttribute="bottom" secondItem="Ic2-yw-Fo7" secondAttribute="bottom" id="zhL-j8-GPY"/>
</constraints>
<viewLayoutGuide key="safeArea" id="hha-gv-ACH"/>
<size key="customSize" width="220" height="123"/>
<connections>
<outlet property="borderView" destination="Ic2-yw-Fo7" id="XwY-SP-k9X"/>
<outlet property="locationLabel" destination="hd0-ZR-rTQ" id="FAX-PA-bdS"/>
<outlet property="titleLabel" destination="TU0-NI-510" id="0qh-cd-bPg"/>
</connections>
<point key="canvasLocation" x="85" y="76"/>
</collectionViewCell>
</objects>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ extension LongPressViewController: JZLongPressViewDelegate, JZLongPressViewDataS
weekView.forceReload(reloadEvents: viewModel.eventsByDate)
}

func weekView(_ weekView: JZLongPressWeekView, movingCell: UICollectionViewCell, didEndMoveLongPressAt startDate: Date) {
let event = (movingCell as! EventCell).event!
func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) {
let event = editingEvent as! Event
let duration = Calendar.current.dateComponents([.minute], from: event.startDate, to: event.endDate).minute!
let selectedIndex = viewModel.events.index(where: { $0.id == event.id })!
viewModel.events[selectedIndex].startDate = startDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class LongPressWeekView: JZLongPressWeekView {
override func registerViewClasses() {
super.registerViewClasses()

self.collectionView.register(UINib(nibName: EventCell.className, bundle: nil), forCellWithReuseIdentifier: EventCell.className)
self.collectionView.register(UINib(nibName: LongPressEventCell.className, bundle: nil), forCellWithReuseIdentifier: LongPressEventCell.className)
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: EventCell.className, for: indexPath) as! EventCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: LongPressEventCell.className, for: indexPath) as! LongPressEventCell
cell.updateView(event: getCurrentEvent(with: indexPath) as! Event)
return cell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RootViewModel: NSObject {
lazy var events = [Event(id: "0", title: "One", startDate: firstDate, endDate: firstDate.add(component: .hour, value: 1), location: "Melbourne", eventType: 0),
Event(id: "1", title: "Two", startDate: secondDate, endDate: secondDate.add(component: .hour, value: 4), location: "Sydney", eventType: 0),
Event(id: "2", title: "Three", startDate: thirdDate, endDate: thirdDate.add(component: .hour, value: 2), location: "Tasmania", eventType: 1),
Event(id: "3", title: "Four", startDate: thirdDate, endDate: thirdDate.add(component: .day, value: 2), location: "Canberra", eventType: 1)]
Event(id: "3", title: "Four", startDate: thirdDate, endDate: thirdDate.add(component: .day, value: 1), location: "Canberra", eventType: 1)]

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

Expand Down
4 changes: 2 additions & 2 deletions Example/JZCalendarWeekViewExample/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CFBundleVersion</key>
<string>1805011500</string>
<string>1805021706</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion JZCalendarWeekView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JZCalendarWeekView"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "Calendar Week & Day View in iOS Swift"
s.homepage = "https://github.com/zjfjack/JZCalendarWeekView"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion JZCalendarWeekView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
8E21E8AF20916A96002D72D0 /* JZLongPressWeekView.swift */,
8E1BA95A206B4826007BE13C /* JZWeekViewFlowLayout.swift */,
8E023C83206C732300C523BE /* JZBaseEvent.swift */,
8E1BA971206B61B7007BE13C /* JZBaseEventCell.swift */,
8E1BA969206B5350007BE13C /* JZWeekViewHelper.swift */,
8E1BA95C206B4AD9007BE13C /* ReusableViews */,
8E1BA955206B4687007BE13C /* Utils */,
Expand All @@ -140,7 +141,6 @@
8E1BA95C206B4AD9007BE13C /* ReusableViews */ = {
isa = PBXGroup;
children = (
8E1BA971206B61B7007BE13C /* JZBaseEventCell.swift */,
8E1BA95F206B4B84007BE13C /* JZColumnHeader.swift */,
8E1BA961206B4B99007BE13C /* JZRowHeader.swift */,
8E1BA963206B4E82007BE13C /* JZCornerHeader.swift */,
Expand Down
2 changes: 1 addition & 1 deletion JZCalendarWeekView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import UIKit

// No Need to subclass, used only for identifier now, will refactor in the future
// If you want to use Move Type LongPressWeekView, you have to subclass this class
open class JZBaseEventCell: UICollectionViewCell {

public var event: JZBaseEvent!


}
Loading

0 comments on commit cb84654

Please sign in to comment.