pkluz / PKHUD

A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8.
MIT License
3.79k stars 494 forks source link

Problem with CoreMotion causes UI API called on a background thread, IPhone X series #251

Closed hackerpex closed 5 years ago

hackerpex commented 5 years ago

this problem just block presentation on ios 12x only int IPhone X series

this part of code was commented and solve the problem

// let motionEffectsX = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis) // motionEffectsX.maximumRelativeValue = offset // motionEffectsX.minimumRelativeValue = -offset // // let motionEffectsY = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis) // motionEffectsY.maximumRelativeValue = offset // motionEffectsY.minimumRelativeValue = -offset

// let group = UIMotionEffectGroup() // group.motionEffects = [motionEffectsX, motionEffectsY] // // addMotionEffect(group)

tarekeg commented 5 years ago

thanks a lot

stefanrenne commented 5 years ago

Wrapping that piece of code with a dispatch async also solves the problem

DispatchQueue.main.async {
     let motionEffectsX = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
     motionEffectsX.maximumRelativeValue = offset
     motionEffectsX.minimumRelativeValue = -offset

     let motionEffectsY = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
     motionEffectsY.maximumRelativeValue = offset
     motionEffectsY.minimumRelativeValue = -offset

     let group = UIMotionEffectGroup()
     group.motionEffects = [motionEffectsX, motionEffectsY]

     self.addMotionEffect(group)
}

Created a PR for this https://github.com/pkluz/PKHUD/pull/252

PGLongo commented 5 years ago

merged the pr

jbmaxwell commented 5 years ago

I'm running 5.2.1 and still get this error. Is it not merged?

jbmaxwell commented 5 years ago

Updated my project to Xcode 10.2, Swift 5, cloned your repo and updated PKHUD to 5.2.2, and same Main Thread Checker error. This is on iPhone XR, btw.