ipad - How to to determinate in Swift the current width of the app when in Split View? -
edit: have project row of buttons on top on it. buttons 5 in compact view , 6 in regular view. remove button when app runs in 1/3 split view. how can determine width of app?
i'm using code determinate current width of app when in split view (multitasking):
override func viewwilltransitiontosize(size: cgsize, withtransitioncoordinator coordinator: uiviewcontrollertransitioncoordinator) { // works it's deprecated: let currentwidth = uiscreen.mainscreen().applicationframe.size.width print(currentwidth) }
it works, unfortunately applicationframe deprecated in ios 9, i'm trying replace this:
override func viewwilltransitiontosize(size: cgsize, withtransitioncoordinator coordinator: uiviewcontrollertransitioncoordinator) { // gives width of screen not width of app: let currentwidth = uiscreen.mainscreen().bounds.size.width print(currentwidth) }
the problem first statement gives effective width of app , it's fine, instead second one, gives width of screen, can't use learn real width of app when in split view.
would know code necessary replace deprecated statement?
let currentwidth = uiscreen.mainscreen().applicationframe.size.width // deprecated
you can size of parent view.
let currentsize = self.view.bounds.width
that return width accurately in split view.
you can determine whether show or hide button.
let totalbuttonwidth: int b in self.collectionview.uiviews{ let totalbuttonwidth += b.frame.width + 20 //where '20' gap between buttons } if (currentsize < totalbuttonwidth){ self.collectionview.subviews[self.collectionview.subviews.count].removefromsuperview() }else{ self.collectionview.addsubview(buttonviewtoadd) }
something that, think can idea.
Comments
Post a Comment