为什么旋转NSImageView会使我的应用程序崩溃?

时间:2017-08-29 15:02:48

标签: macos nsimageview

我正在制作一个macOS应用,而且我已经将这段代码用于旋转图片:

didSet {
        let degreesToRotate = oldValue - phoneXRotation
        phoneImageView.rotate(byDegrees: CGFloat(degreesToRotate))
        degreesLabel.isHidden = false
        degreesLabel.stringValue = "\(phoneXRotation)"
        if phoneXRotation > 70 {
            statusLabel.stringValue = "Phone orientation: Right Tilt"
        } else if phoneXRotation < -70 {
            statusLabel.stringValue = "Phone orientation: Left Tilt"
        } else {
            statusLabel.stringValue = "Phone orientation: Flat"
        }
    }

应用程序将在lldb错误中随机崩溃。如果我注释掉旋转手机的第三行,我没有问题。从Int到CGFloat的转换不应该崩溃。有什么想法吗?

这是堆栈跟踪:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #0: 0x00007fff8989b44e AppKit`-[NSApplication _crashOnException:] + 109
frame #1: 0x00007fff8996ea32 AppKit`__37+[NSDisplayCycle currentDisplayCycle]_block_invoke.31 + 708
frame #2: 0x00007fff8ba62d37 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
frame #3: 0x00007fff8ba62ca7 CoreFoundation`__CFRunLoopDoObservers + 391
frame #4: 0x00007fff8ba436d9 CoreFoundation`__CFRunLoopRun + 873
frame #5: 0x00007fff8ba43114 CoreFoundation`CFRunLoopRunSpecific + 420
frame #6: 0x00007fff8afa3ebc HIToolbox`RunCurrentEventLoopInMode + 240
frame #7: 0x00007fff8afa3cf1 HIToolbox`ReceiveNextEventCommon + 432
frame #8: 0x00007fff8afa3b26 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 71
frame #9: 0x00007fff8953ca54 AppKit`_DPSNextEvent + 1120
frame #10: 0x00007fff89cb87ee AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
frame #11: 0x00007fff895313db AppKit`-[NSApplication run] + 926
frame #12: 0x00007fff894fbe0e AppKit`NSApplicationMain + 1237
* frame #13: 0x000000010000691d Dataspeed Mac Project`main at AppDelegate.swift:12
frame #14: 0x00007fffa11f1235 libdyld.dylib`start + 1
frame #15: 0x00007fffa11f1235 libdyld.dylib`start + 1

0 个答案:

没有答案