gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:58:19 26 4
gpt4 key购买 nike

当我将其范围从每周切换到每月时,如果存在仅限于其底部 anchor 的 View ,我的 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))
}

}

最佳答案

好吧,我不知道如何解决问题本身,但我确实找到了解决方法。我将日历放置在一个空容器 View (只是一个简单的 UIView)中,并将 attachedToCalendarView 附加到容器的 bottomAnchor 而不是日历本身。

但请注意,使用设置过渡动画的 setScope 仍然会导致相同的问题。为了让它工作,你必须像 calendar.scope = x

手动设置它

示例:

@objc func switchCalendarScope(){
if self.calendar.scope == FSCalendarScope.month {
// self.calendar.setScope(FSCalendarScope.week, animated: true) // this will cause the calendar to be squished again
self.calendar.scope = .week
movingConstraint.constant = view.safeAreaLayoutGuide.layoutFrame.size.height * -0.20
} else {
// self.calendar.setScope(FSCalendarScope.month, animated: true)
self.calendar.scope = .month
movingConstraint.constant = 0
}
}

关于ios - 当我将范围切换到月份时,FSCalendar 内容被压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53691601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com