gpt4 book ai didi

ios - 使用 setContentOffSet 按钮滚动

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

我正在尝试找出 ScrollView 以及如何使它们以编程方式滚动。

我在一个 View Controller 中设置了 2 个屏幕( ImageView )。 enter image description here enter image description here

我通过选择顶部、底部、左侧和右侧以及高度和宽度来向 ImageView 和 ScrollView 添加约束。

我的 View Controller 有这个

import UIKit

class ViewController: UIViewController {
var scrollView: UIScrollView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override var prefersStatusBarHidden: Bool {
return true
}

@IBAction func toFloorplan(_ sender: Any) {
scrollView.setContentOffset(CGPoint(x:1366, y:0), animated: false)
}}

和一个调用 toFloorPlan 的简单按钮。

我可以使用分页左右滚动,但是当我单击按钮时,我的应用程序退出并得到以下打印结果。感谢您的帮助!!

2017-03-30 18:20:13.423801 VHThenNow[78847:14546188] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", "", "" )

Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

最佳答案

@IBOutlet weak var scrollView: UIScrollView!  

并创建 socket - 将 Storyboard中的 ScrollView 与 ScrollView 变量连接起来。
您的约束错误,但它不是崩溃的原因

关于ios - 使用 setContentOffSet 按钮滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43111253/

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