在 Swift 4 中执行此操作的最佳方法是什么?
我还是菜鸟水平。到目前为止,我在滚动视图中有一个文本视图。我已经关闭了默认的水平和垂直滚动,并使用 UIEdgeInsets 在文本周围添加了填充。
在 Swift 4 中执行此操作的最佳方法是什么?
我还是菜鸟水平。到目前为止,我在滚动视图中有一个文本视图。我已经关闭了默认的水平和垂直滚动,并使用 UIEdgeInsets 在文本周围添加了填充。
轮换后您需要设置一些约束,但除此之外,我认为这会起作用。我会尝试以下方法:
@IBOutlet weak var slider: UISlider! {
didSet {
configureSlider()
}
}
//Actually rotates the slider
func configureSlider() {
slider.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi / 2))
// Probably add some constraints here
}
// Create an action, and make sure the sender is a UISlider so you have access to the .value property
@IBAction func valueDidChange(_ sender: UISlider) {
let contentSize = scrollView.contentSize.height
let yPosition = contentSize * CGFloat(sender.value)
scrollView.setContentOffset(CGPoint(x: 0, y: yPosition), animated: true)
}
试试看。最好的祝愿!
从它的外观来看,您可以使用UISlider垂直放置在滚动视图旁边,当值UISlider更改时,您可以更改UIScrollview滚动视图的偏移量。