Loading a UIDatePicker in Landscape on a UINavigationController

前端 未结 6 661
慢半拍i
慢半拍i 2021-02-14 20:44

I have a custom UINavigationController that supports auto-rotate. I also have a UIDatePicker on one of my views that I throw onto the stack of the Navigation controller. The a

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 21:01

    Here's what worked for me. When I create the DatePicker, I make it think it's in portrait mode:

    [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait  animated: NO];
    datePicker = [[UIDatePicker alloc] initWithFrame: CGRectZero];
    [[UIApplication sharedApplication] setStatusBarOrientation: curOrientation animated: NO];
    

    So basically, I change the orientation, create the datePicker, and change the orientation back right away to what it was before. I set the picker width (screen width) and height (216) elsewhere.

    I got this clue from another page.

提交回复
热议问题