声明button.frame时EXC_BAD_INSTRUCTION

时间:2016-06-16 17:17:08

标签: ios swift

当我试图宣布

时,我收到错误消息 Thread1:EXC_BAD_INSTRUCTION(code = EXC_1386_INVOP,subcode = 0x0)
    var buttonFrame = customButton.frame

这是我的代码。任何帮助表示赞赏。

override func viewDidLoad() {
    super.viewDidLoad()

    //sends menuOverlay to back on load
    parentView.sendSubviewToBack(menuOverlay)
    self.menuOverlay.hidden = true

    //sends sliderContainer back and makes its origin at the button
    let containerFrame = sliderContainer.frame

    let containerFrameX = containerFrame.minX
    let containerFrameY = containerFrame.minY

    var buttonFrame = customButtonOne.frame

    let sliderOriginX = buttonFrame.minX + (buttonFrame.width / 2)
    let containerTranslationX = CGFloat(containerFrameX-sliderOriginX)
    let containerTranslationY = CGFloat(-containerFrameY)

    self.sliderContainer.transform = CGAffineTransformMakeScale(0.001, 0.001)
    self.sliderContainer.transform = CGAffineTransformMakeTranslation(containerTranslationX, containerTranslationY)
}

1 个答案:

答案 0 :(得分:0)

如果customButtonOne是未连接的IBOutlet,则为nilnil没有frame属性,因此崩溃。

确保您的IBOutlet已连接。