我正在使用CVCalendar来显示日历。我想在日历视图中禁用滑动操作。怎么可能?
以下代码调用cvcalendar并显示日历。我有两个按钮和nex并且可以更改月视图。
import UIKit
class CalendarViewController: UIViewController {
@IBOutlet weak var menuView: CVCalendarMenuView!
@IBOutlet weak var calendarView: CVCalendarView!
@IBOutlet weak var monthLabel: UILabel!
@IBOutlet weak var eventTableView: UITableView!
var event : String = "1"
var shouldShowDaysOut = true
var animationFinished = true
override func viewDidLoad() {
super.viewDidLoad()
monthLabel.text = CVDate(date: NSDate()).globalDescription
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calendarView.commitCalendarViewUpdate()
menuView.commitMenuViewUpdate()
}
}
/*
* CVCalendar library functions to display calender and events
*/
extension CalendarViewController: CVCalendarViewDelegate , MenuViewDelegate {
func presentationMode() -> CalendarMode {
return .MonthView
}
func firstWeekday() -> Weekday {
return .Sunday
}
func shouldShowWeekdaysOut() -> Bool {
return false
}
func didSelectDayView(dayView: CVCalendarDayView) {
let date = dayView.date
if dayView.isCurrentDay {
eventTableView.hidden = false
eventTableView.reloadData()
}
else {
eventTableView.hidden = true
}
println("\(calendarView.presentedDate.commonDescription) is selected!")
}
func presentedDateUpdated(date: CVDate) {
if monthLabel.text != date.globalDescription && self.animationFinished {
let updatedMonthLabel = UILabel()
updatedMonthLabel.textColor = monthLabel.textColor
updatedMonthLabel.font = monthLabel.font
updatedMonthLabel.textAlignment = .Center
updatedMonthLabel.text = date.globalDescription
updatedMonthLabel.sizeToFit()
updatedMonthLabel.alpha = 0
updatedMonthLabel.center = self.monthLabel.center
let offset = CGFloat(48)
updatedMonthLabel.transform = CGAffineTransformMakeTranslation(0, offset)
updatedMonthLabel.transform = CGAffineTransformMakeScale(1, 0.1)
UIView.animateWithDuration(0.35, delay: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
self.animationFinished = false
self.monthLabel.transform = CGAffineTransformMakeTranslation(0, -offset)
self.monthLabel.transform = CGAffineTransformMakeScale(1, 0.1)
self.monthLabel.alpha = 0
updatedMonthLabel.alpha = 1
updatedMonthLabel.transform = CGAffineTransformIdentity
}) { _ in
self.animationFinished = true
self.monthLabel.frame = updatedMonthLabel.frame
self.monthLabel.text = updatedMonthLabel.text
self.monthLabel.transform = CGAffineTransformIdentity
self.monthLabel.alpha = 1
updatedMonthLabel.removeFromSuperview()
}
self.view.insertSubview(updatedMonthLabel, aboveSubview: self.monthLabel)
}
}
func topMarker(shouldDisplayOnDayView dayView: CVCalendarDayView) -> Bool {
return false
}
func dotMarker(shouldShowOnDayView dayView: CVCalendarDayView) -> Bool {
let day = dayView.date.day
if dayView.isCurrentDay{
return true
}
return false
}
func dotMarker(colorOnDayView dayView: CVCalendarDayView) -> [UIColor] {
let day = dayView.date.day
let color = UIColor.greenColor()
return [color]
}
func dotMarker(shouldMoveOnHighlightingOnDayView dayView: CVCalendarDayView) -> Bool {
return false
}
}
// MARK: - CVCalendarViewAppearanceDelegate
extension CalendarViewController: CVCalendarViewAppearanceDelegate {
func dayLabelPresentWeekdayInitallyBold() -> Bool {
return true
}
func spaceBetweenDayViews() -> CGFloat {
return 2
}
}
@IBAction func next(sender: AnyObject) {
calendarView.loadNextView()
}
@IBAction func previous(sender: AnyObject) {
calendarView.loadPreviousView()
}
答案 0 :(得分:1)
您可以通过以下方式禁用CVCalendarView
的滚动:
转到CVCalendarContentViewController.swift
,然后找到扩展程序CVCalendarContentViewController
。
在该扩展程序中,通过替换此行来更改scrollView
的大小:
scrollView.contentSize = CGSizeMake(frame.size.width * 3, frame.size.height)
使用以下代码:
scrollView.contentSize = CGSizeMake(frame.size.width, frame.size.height)
希望它会有所帮助。
<强>更新强>
转到项目导航器,单击第三个图标,即Find Navigator,如下图所示:
并将此行搜索到该textField:
scrollView.contentSize = CGSizeMake(frame.size.width * 3, frame.size.height)
你的结果将是这样的:
单击该结果并用该行替换该行:
scrollView.contentSize = CGSizeMake(frame.size.width, frame.size.height)