Pop over doesn't point over the button

前端 未结 3 527
遥遥无期
遥遥无期 2021-02-05 03:49

I have an application that is compatible with both iPhone and iPad layouts. For iPhone layout I have created Action Sheet and Pop over for iPad. The problem is pop over\'s arrow

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-05 04:24

    SWIFT 3

    This worked for me when my button was a UIBarButtonItem:

    if UIDevice.current.userInterfaceIdiom == .pad {
    
        if controller.responds(to: "popoverPresentationController") {
            controller.popoverPresentationController?.barButtonItem = YourUIBarButtonName
        }
    
    }
    

    Entire code snippet below:

    func presentActivitySheet() {
    
        let controller = UIActivityViewController(activityItems: [document.fileURL], applicationActivities: nil)
    
            if UIDevice.current.userInterfaceIdiom == .pad {
    
                if controller.responds(to: "popoverPresentationController") {
                controller.popoverPresentationController?.barButtonItem = YourUIBarButtonName
                }
    
            }
    
        present(controller, animated: true, completion: nil)
    }
    

提交回复
热议问题