当我将范围切换到月份时,FSCalendar内容被压缩

时间:2018-12-09 10:59:52

标签: ios swift swift4 fscalendar

如果将视图限制在其底部锚点上,那么我将FSCalendar的范围从一周切换到一个月时,我的FSCalendar的内容就会缩小。

这是一个快速的gif,可以显示正在发生的事情

GIF

我现在已经尝试了一切。使用calendar.setScope()代替calendar.scope =,将attachedToCalendarView.topAnchor约束为calendar.bottomAnchor calendar.contentView.bottomAnchorcalendar.daysContainer.bottomAnchor,甚至将attachedToCalendarView的约束设为并根据星期范围或范围月份而关闭。

不确定其他尝试方法。这是代码:

import UIKit
import FSCalendar

class TestController : UIViewController, FSCalendarDataSource, FSCalendarDelegate, FSCalendarDelegateAppearance {

fileprivate weak var calendar: FSCalendar!

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .white
    setUp()
}


@objc func switchCalendarScope(){
    if self.calendar.scope == FSCalendarScope.month {
        self.calendar.scope = FSCalendarScope.week

    } else {
        self.calendar.scope = FSCalendarScope.month
    }

}

func setUp(){

    let calendar = FSCalendar()
    calendar.dataSource = self
    calendar.delegate = self
    self.calendar = calendar

    self.calendar.scope = .week
    self.calendar.locale = Locale(identifier: "en_EN")
    self.calendar.calendarHeaderView.calendar.locale =  Locale(identifier: "en_EN")
    self.calendar.adjustsBoundingRectWhenChangingMonths = true

    let testingView = UIView()
    testingView.backgroundColor = .red

    let attachedToCalendarView = UIView()
    attachedToCalendarView.backgroundColor = .blue

    view.addSubview(calendar)
    view.addSubview(testingView)
    view.addSubview(attachedToCalendarView)

    self.calendar.translatesAutoresizingMaskIntoConstraints = false
    self.calendar.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    self.calendar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
    self.calendar.widthAnchor.constraint(equalToConstant: view.bounds.size.width).isActive = true
    self.calendar.heightAnchor.constraint(equalToConstant: 300).isActive = true

    testingView.translatesAutoresizingMaskIntoConstraints = false
    testingView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    testingView.widthAnchor.constraint(equalToConstant: view.bounds.size.width).isActive = true
    testingView.heightAnchor.constraint(equalToConstant: 20).isActive = true

    attachedToCalendarView.translatesAutoresizingMaskIntoConstraints = false
    attachedToCalendarView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    // Attaching this view's topAnchor to the calendar's bottom anchor
    attachedToCalendarView.topAnchor.constraint(equalTo: self.calendar.contentView.bottomAnchor).isActive = true
    attachedToCalendarView.widthAnchor.constraint(equalToConstant: view.bounds.size.width).isActive = true
    attachedToCalendarView.heightAnchor.constraint(equalToConstant: 20).isActive = true


    // Title and button to toggle the calendar scope
    self.navigationItem.title = "Test"
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Toggle", style: .done, target: self, action: #selector(switchCalendarScope))
}

}

1 个答案:

答案 0 :(得分:0)

好吧,我不知道该如何解决问题本身,但确实找到了解决方法。我将日历放在一个空的容器视图(只是一个简单的UIView)中,并将public void run() throws Exception { try { final String ConnectionString = "<My connection String> "; final String QueueName = "queue1"; QueueClient sendClient = new QueueClient(new ConnectionStringBuilder(ConnectionString, QueueName), ReceiveMode.PEEKLOCK); System.out.println("sendClient created"); sendClient.close(); } catch(Exception e) { System.err.println(e); } } 附加到容器的attachedToCalendarView而不是日历本身。

但是请注意,使用bottomAnchor为过渡设置动画仍然会导致相同的问题。要使其正常工作,您必须像setScope

那样手动设置

示例:

calendar.scope = x