首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将代码更新为xcode 9和swift 4后应用程序崩溃

将代码更新为xcode 9和swift 4后应用程序崩溃
EN

Stack Overflow用户
提问于 2017-10-10 10:35:34
回答 1查看 635关注 0票数 1

在将项目升级到xcode 9和swift 4之后,应用程序崩溃。

代码语言:javascript
运行
复制
    backview.addsubview(stackview)

应用程序与libc++abi.dylib崩溃:以NSException类型的完全例外终止。代码在NSException 3中运行得很好。但是在迁移到with 4之后,它就崩溃了。这就是我的全部功能。

代码语言:javascript
运行
复制
    var isAlreadyThere = false

    if let audioView = self.view.subviews.filter (
        { $0.tag == 123456}).first  {

        audioView.tag = 123456
        isAlreadyThere = true
    }

    if isAlreadyThere {
        return
    }

    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
    let backView = UIVisualEffectView(effect: blurEffect)
    backView.tag = 123456
    backView.frame = CGRect(x: 0, y: self.view.frame.height+35 , width: self.view.frame.width, height: 40)
    backView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    view.addSubview(backView)

    pauseButton = UIButton(type: .custom)
    pauseButton.titleLabel?.font = Util.getFontSize()
    pauseButton.setTitle("Pause", for: .normal)
    pauseButton.setTitleColor(UIColor.black, for: .normal)
    pauseButton.addTarget(self, action: #selector(pausePressed(_:)), for: .touchDown)

    durationLabel = UILabel()
    durationLabel.textColor = UIColor.black
    durationLabel.font = Util.getFontSize()
    durationLabel.textAlignment = .center
    durationLabel.text = "0:00"

    stopButton = UIButton(type: .custom)
    stopButton.titleLabel?.font = Util.getFontSize()
    stopButton.setTitle("Stop", for: .normal)
    stopButton.setTitleColor(UIColor.black, for: .normal)
    stopButton.addTarget(self, action: #selector(stopPressed(_:)), for: .touchDown)

    let stackView = UIStackView(frame: CGRect(x: 0, y:0 , width: backView.frame.width, height: 40))
    stackView.alignment = .fill
    stackView.axis = .horizontal
    stackView.distribution = .fillEqually
    stackView.spacing = 5
    stackView.addArrangedSubview(pauseButton)
    stackView.addArrangedSubview(durationLabel)
    stackView.addArrangedSubview(stopButton)

    backView.addSubview(stackView)

    if audioViewYposition == nil {
        audioViewYposition = self.view.frame.height - 40
    }

    UIView.animate(withDuration: 0.2, delay: 0.1, options: .curveEaseInOut, animations: {
        backView.frame.origin.y = self.audioViewYposition
    }, completion: nil)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-10 10:55:30

正如在“错误”中指出的,您需要在“内容”视图上添加一个子视图,而不是直接在“视觉效果”视图上添加子视图,因此解决方案是:

代码语言:javascript
运行
复制
backView.contentView.addSubview(stackView)

请确保是否启用了异常断点以跳过断点中的几个帧,以查看控制台中的错误消息:

代码语言:javascript
运行
复制
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: '<UIStackView: 0x109946ff0; frame = (0 0; 375 40); layer = <CATransformLayer: 0x1c4236640>> 
has been added as a subview to 
<UIVisualEffectView: 0x109945f40; frame = (0 702; 375 40); autoresize = W+H; tag = 123456; layer = <CALayer: 0x1c002ebc0>>. 
Do not add subviews directly to the visual effect view itself, 
instead add them to the -contentView.'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46664582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档