ios - Why isn't preferredContentSize used by iPhone 6 Plus Landscape? -
in ios 8 app, popover segue appears correctly on devices in orientations except iphone 6 plus landscape:

this how looks on iphone 6 plus landscape (it stretching top bottom): 
and when displays this, clicking outside of view doesn't dismiss (although cancel work). rotating portrait gets normal.
all of constraints in uiviewcontroller installed on size classes.
when debugging values in viewdidappear: see following:
- po self.view: frame = (0 0; 250 394)
- po self.preferredcontentsize (width = 250, height = 160)
what causing view's height jump 394?
i'm having same issue popover segue in iphone 6 plus landscape well. (and in case there curiosity, i'm using vc instead of 'uialertcontroller' here because of validation requirements of uitextfield displayed don't work uialertcontroller.)
edit include popover code:
this code found in prepareforsegue:
favoritenameviewcontroller *namevc = segue.destinationviewcontroller; uipopoverpresentationcontroller *poppc = namevc.popoverpresentationcontroller; poppc.delegate = self; namevc.delegate = self; namevc.view.center = self.originalcontentview.center; and delegate method:
- (uimodalpresentationstyle)adaptivepresentationstyleforpresentationcontroller:(uipresentationcontroller *)controller { return uimodalpresentationnone; } and here segue definition in xcode: 
what you're seeing not popover. it's normal presented view. default, popover appears popover on ipad, presented view on iphone — including iphone 6 plus. on other iphones, presented view fullscreen - covers everything. iphone 6 wide don't that, appears in middle of screen @ standard width (the width of smaller iphone).
thus, preferred content size has no effect. isn't popover. presented view controller views given standard size, , 1 no exception.
however, can have popover appear as popover on iphone. so:
set delegate popover view controller's
popoverpresentationcontrollerbefore presenting it.in delegate, implement
adaptivepresentationstyleforpresentationcontroller:, return.none.
however, apparently not working on iphone 6 plus in landscape mode; popover not "adapting". describe bug!
edit in ios 9, the problem solved! implement new delegate method adaptivepresentationstyleforpresentationcontroller:traitcollection: return .none , you'll popover under circumstances, including iphone 6 plus in landscape. here's complete working example popover created , summoned in code in response button tap:
@ibaction func dobutton(sender: anyobject) { let vc = myviewcontroller() vc.preferredcontentsize = cgsizemake(400,500) vc.modalpresentationstyle = .popover if let pres = vc.presentationcontroller { pres.delegate = self } self.presentviewcontroller(vc, animated: true, completion: nil) if let pop = vc.popoverpresentationcontroller { pop.sourceview = (sender as! uiview) pop.sourcerect = (sender as! uiview).bounds } } func adaptivepresentationstyleforpresentationcontroller( controller: uipresentationcontroller, traitcollection: uitraitcollection) -> uimodalpresentationstyle { return .none } 
Comments
Post a Comment