swift playground UITextField spawns keyboard that is too big

前端 未结 3 631
再見小時候
再見小時候 2021-02-08 04:26

Swift in playground on Mac OS. When the user clicks in a UItextfield, a keyboard spawns but it is very large compared to the view and only the first few keys are available.

相关标签:
3条回答
  • 2021-02-08 05:05

    In reply to Adobels (Seo 21 '19) ...

    I am not sure why he proposed a different approach.

    I modified dr_barlo's approach of Oct 22 '17 as follows (and it works in Xcode 11 too):

    let vc = TextFieldViewController()
    vc.preferredContentSize = CGSize.init(width: 768,height: 1024)
    PlaygroundPage.current.liveView = vc
    

    They all appear equivalent in results if not internal workings.

    0 讨论(0)
  • 2021-02-08 05:11

    Instead this line

    PlaygroundPage.current.liveView = MyViewController()
    

    Write this

    let window = UIWindow(frame: CGRect(x: 0,
                                        y: 0,
                                        width: 768,
                                        height: 1024))
    let viewController = MyViewController()
    window.rootViewController = viewController
    window.makeKeyAndVisible()
    
    PlaygroundPage.current.liveView = window
    

    It works in Xcode 11

    0 讨论(0)
  • 2021-02-08 05:13

    I face the same issue. It seems as if Playground has a hard-coded screen size of 768x1024 (run UIScreen.main.bounds in the Playground) and shows the keyboard according to this size, independently of the live view's actual size.

    The best workaround I came up with is to increase the size of the view controller so that it matches the keyboard:

    let vc = TesterViewController()
    vc.preferredContentSize = vc.view.frame.size // or a custom CGSize
    PlaygroundPage.current.liveView = vc
    

    Of course this makes the view larger than you might want it to be, so I only use this workaround when I really have to access the on-screen keyboard for testing.

    0 讨论(0)
提交回复
热议问题