Ios 编辑文本字段时是否偏移滚动视图?
我目前正试图在键盘弹出时使滚动视图偏移。但是,当我开始编辑我设置为代理的文本字段时,它会使应用程序崩溃。感谢您的帮助Ios 编辑文本字段时是否偏移滚动视图?,ios,swift3,uitextfield,uikeyboard,uitextfielddelegate,Ios,Swift3,Uitextfield,Uikeyboard,Uitextfielddelegate,我目前正试图在键盘弹出时使滚动视图偏移。但是,当我开始编辑我设置为代理的文本字段时,它会使应用程序崩溃。感谢您的帮助 class ViewController: UIViewController, UITextFieldDelegate{ @IBOutlet weak var scroll: UIScrollView! @IBOutlet weak var bottomText: UITextField! override func viewDidLoad() { su
class ViewController: UIViewController, UITextFieldDelegate{
@IBOutlet weak var scroll: UIScrollView!
@IBOutlet weak var bottomText: UITextField!
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.
}
func textFieldDidBeginEditing(_ textField: UITextField) {
//scroll.setContentOffset(CGPoint(x: 0,y: 250), animated: true)
print("test")
}
}
这是日志的截图
这是完整的堆栈跟踪
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x0000000105efb237 TestingScrollView`ViewController.textFieldDidBeginEditing(textField=0x00007fcf807065e0, self=0x00007fcf8040de90) -> () at ViewController.swift:27
frame #1: 0x0000000105efb31a TestingScrollView`@objc ViewController.textFieldDidBeginEditing(UITextField) -> () at ViewController.swift:0
frame #2: 0x0000000107d40970 UIKit`-[UITextField _becomeFirstResponder] + 641
frame #3: 0x0000000107457e21 UIKit`-[UIResponder becomeFirstResponder] + 436
frame #4: 0x00000001072f12f7 UIKit`-[UIView(Hierarchy) becomeFirstResponder] + 137
frame #5: 0x0000000107d3f956 UIKit`-[UITextField becomeFirstResponder] + 50
frame #6: 0x00000001077856d2 UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 208
frame #7: 0x0000000107788e28 UIKit`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 3772
frame #8: 0x0000000107776c09 UIKit`-[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
frame #9: 0x000000010777ea07 UIKit`_UIGestureRecognizerSendTargetActions + 109
frame #10: 0x000000010777c3bb UIKit`_UIGestureRecognizerSendActions + 225
frame #11: 0x000000010777b67e UIKit`-[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 981
frame #12: 0x0000000107767e02 UIKit`_UIGestureEnvironmentUpdate + 1219
frame #13: 0x00000001077678f3 UIKit`-[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
frame #14: 0x0000000107766aba UIKit`-[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
frame #15: 0x00000001072b2b9a UIKit`-[UIWindow sendEvent:] + 4092
frame #16: 0x000000010725f7b0 UIKit`-[UIApplication sendEvent:] + 352
frame #17: 0x0000000107a42adc UIKit`__dispatchPreprocessedEventFromEventQueue + 2926
frame #18: 0x0000000107a3aa3a UIKit`__handleEventQueue + 1122
frame #19: 0x0000000109263c01 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
frame #20: 0x00000001092490cf CoreFoundation`__CFRunLoopDoSources0 + 527
frame #21: 0x00000001092485ff CoreFoundation`__CFRunLoopRun + 911
frame #22: 0x0000000109248016 CoreFoundation`CFRunLoopRunSpecific + 406
frame #23: 0x000000010b1c8a24 GraphicsServices`GSEventRunModal + 62
frame #24: 0x00000001072420d4 UIKit`UIApplicationMain + 159
frame #25: 0x0000000105efc797 TestingScrollView`main at AppDelegate.swift:12
frame #26: 0x000000010a25d65d libdyld.dylib`start + 1
frame #27: 0x000000010a25d65d libdyld.dylib`start + 1
(lldb)
下面是错误的屏幕截图
哇-应用程序在意外设置的断点处停止。易于操作: ⌘+\
将在当前行设置(实际上是切换)断点。是否检查了scroll的值?崩溃在控制台中记录的堆栈跟踪是什么?@Pacu I添加了日志的屏幕截图。你所说的检查卷轴的价值是什么意思?最初我确实让它的高度为1000,但我删除了它,因为我认为我不应该特别需要它来完成这个简单的任务。我是说在调试器上。另外,粘贴所描述的崩溃的堆栈跟踪也是很重要的。90%的情况下,它是解决问题的线索,我粘贴了完整的堆栈跟踪(希望我对这个术语和Xcode基本上是新手)。此外,我还通过调试器查看了日志,但我不完全确定检查scroll值需要什么。它说它是活动的,并且有几个约束。复制崩溃并粘贴堆栈跟踪。