“在Swift中从主线程访问引擎后,此应用程序正在从后台线程修改自动布局引擎”

时间:2017-04-26 13:49:09

标签: ios swift view position dispatch-async

我正在将视图和此视图的位置更改回第一个位置并提供此输出:

This application is modifying the autolayout engine from a background thread 
after the engine was accessed from the main thread. 
This can lead to engine corruption and weird crashes.

Stack:(
    0   CoreFoundation                      0x000000019083aff0 <redacted> + 148
    1   libobjc.A.dylib                     0x000000018f29c538 objc_exception_throw + 56
    2   CoreFoundation                      0x000000019083af20 <redacted> + 0
    3   Foundation                          0x000000019142c338 <redacted> + 128
    4   Foundation                          0x00000001912749e8 <redacted> + 36
    5   UIKit                               0x00000001972c3e54 <redacted> + 72
    6   UIKit                               0x0000000196967120 <redacted> + 1144
    7   QuartzCore                          0x0000000193b57274 <redacted> + 148
    8   QuartzCore                          0x0000000193b4bde8 <redacted> + 292
    9   QuartzCore                          0x0000000193b4bca8 <redacted> + 32
    10  QuartzCore                          0x0000000193ac7360 <redacted> + 252
    11  QuartzCore                          0x0000000193aee3c0 <redacted> + 504
    12  QuartzCore                          0x0000000193aee6ec <redacted> + 244
    13  libsystem_pthread.dylib             0x000000018f8fbef0 <redacted> + 572
    14  libsystem_pthread.dylib             0x000000018f8fbc18 <redacted> + 200
    15  libsystem_pthread.dylib             0x000000018f8fb2a8 _pthread_wqthread + 1312
    16  libsystem_pthread.dylib             0x000000018f8fad7c start_wqthread + 4
)

我的控制器中也有这个代码:

DispatchQueue.global(qos: .userInitiated).async {
    //some codes which i been waiting

    DispatchQueue.main.async {
        //some codes wait done        
    }

}

我改变的位置代码(它的平移手势):

@IBAction func panSearchView(_ sender: UIPanGestureRecognizer) {        
    let translation = sender.translation(in: self.view)

    var y = sender.view!.center.y + translation.y       
    if y > self.view.frame.size.height - 50 {
        y = self.view.frame.size.height - 50
    }else if y < 200{
        y = 200
    }

    sender.view!.center = CGPoint(x: self.view!.center.x, y: y)        
    sender.setTranslation(CGPoint.zero, in: self.view)

}

我该如何解决这个问题?

0 个答案:

没有答案