繁体   English   中英

[Swift-iOS]使用 UIPanGestureRecognizer 向下拖动视图,不拉伸

[英][Swift-iOS]Dragging down view using UIPanGestureRecognizer, not stretching

我正在尝试向下拖动特定视图以使高度 go 比使用 UIPanGestureRecognizer 之前更长。 但是,它会继续恢复到我最初编程的正常大小。 我试图拉伸的视图不断摇晃并回到初始高度。 任何猜测为什么?

    let CalendarDrag = UIPanGestureRecognizer(target: self, action: #selector(didDragCalendar))
    lineView.isUserInteractionEnabled = true
    lineView.addGestureRecognizer(CalendarDrag)

}


@objc func didDragCalendar(sender: UIPanGestureRecognizer) {
    let velocity = sender.velocity(in: self.view) //속도
    let translation = sender.translation(in: self.view) //위치
    let height = self.topView.frame.maxY
    
    if sender.state == .ended{
        if velocity.y>0{
            calendar.scope = .month
            print("down")
        }else{
            calendar.scope = .week
            print("up")
        }
    }else{
        if height <= height+translation.y && height+translation.y <= height+230{
            self.topView.frame = CGRect(x: 0, y: 0, width: self.topView.frame.width, height: height+translation.y)
            UIView.animate(withDuration: 0, animations: {
                self.view.layoutIfNeeded()
                sender.setTranslation(CGPoint.zero, in: self.view)
            })
        }
    }
}

有关更多信息,我现在正在尝试根据用户制作的 UIPanGesture 使 FSCalendar 在“月”和“周”视图中显示。

您正在更改视图的框架高度。 不要那样做。

将实例变量设置为高度约束,并更改该约束的常量值。 然后,当您从 animation 调用layoutIfNeeded()时,约束将为您更改身高。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM