简体   繁体   中英

Swift - A strange UIView instant covering over the whole top most ViewController

I just updated my Xcode to 8.2.1 and migrated my swift codes from 2.2 to 3.0.

After that, I ran into a situation that my top-most view controller was covered by a view ( for more detail, please click to see the screenshot of Xcode debug hierarchy view ), which never appeared when swift 2.2 was used. The top most VC is a DrawerController from https://cocoapods.org/pods/DrawerController , and is updated to the last version.

Because every touch event was received by the strange view, my app can't work normally.

Is there any potential reason to make the view there? Or is there any way to find out where the view come from?

If more information is needed, please let me know. Thank you in advance.

For lack of reputation, I can't comment.

Have you ever tried to delete this "strange view"? Or just move it on top the UIView that contains your drawer?

I resolved this problem.

In my original codes, I subclassed DrawerController (say, MyDrawerController) and assigned the property centerViewController (the main page shown to the user in DrawerController) in the overrided viewDidLoad() in MyDrawerController. As a result, I ran into the trouble as described in my question above.

What I do to resolve the problem is make a main queue and move the codes which assigning the property centerViewController to the block of the main queue. (Codes of "BEFORE" and "AFTER" like bellow.)

Then, the problem was solved.

Don't know why the "BEFORE" codes worked fine in Swift 2.2 but failed in Swift 3.3. Could anyone tell the difference?

Thanks for your helping.

BEFORE:

class MyDrawerController: DrawerController {

    override func viewDidLoad() {  
        self.centerViewController = aViewControllerInstant 
    } 

}

AFTER:

class MyDrawerController: DrawerController {

    override func viewDidLoad() {  

        DispatchQueue.main.async {
           self.centerViewController = aViewControllerInstant 
        }

    } 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM