ios - iPad Device orientation using statusBarOrientation -
ios - iPad Device orientation using statusBarOrientation -
(xcode 6, swift, ios8)
i trying find device orientation ipad, , seems needlessly complicated. going wrong?
at first, tried utilize interfaceorientation
of uiviewcontroller, unreliable , deprecated. apple recommend using statusbarorientation property. (1)
statusbarorientation of type uiapplication
. tried create instance so:
var o: uiapplication
and test:
if (o.statusbarorientation.islandscape) { ... }
but received error
variable 'o' used before beingness initialized.
which makes no sense me @ all. why initialize value? overwrite value want!?
then tried creating variable recommended in docs:
var statusbarorientation: uiinterfaceorientation
but on trace:
statusbarorientation = (uikit.uiinterfaceorientation) (0xa0)
so tried subclass uiapplication, , access property through subclass.
from here, more complexity. appears "every app must have 1 instance of uiapplication (or subclass of uiapplication)." (2)
this led me next post, seems create main
routine in swift?! subclass uiapplication swift
again, goal grab current device orientation, , test in conditional. pseudocoded:
var o = (get device orientation) if (o == portrait ) { ... } else { ... }
as can see, i'm in weeds... help appreciated.
edit: did manage sort-of working following:
var o = uiapplication.sharedapplication().statusbarorientation; if (o.islandscape) { ...
however, on initial load, when device rotated landscape, o.islandscape
beingness reported false
.
search documentation "uiviewcontroller," , in "configuring view rotation settings." under discussion
, "do not utilize property informing layout decisions. instead, utilize statusbarorientation
property, described in uiapplication class reference."
search documentation "uiapplication" , under subclassing notes
there appear couple of things wrong here i'll seek clear up. first of all, next doesn't create instance of uiapplication, simply variable of type.
var o: uiapplication
if want create instance of uiapplication, should doing this.
let o: uiapplication = uiapplication()
from there, correctly discovered, shouldn't creating additional instances of uiapplication. instead, should accessing singleton instance, sharedapplication()
.
note: have same issue orientation variable did app delegate variable.
anyway, when set together, can current status bar orientation following.
if allow theappdelegate = uiapplication.sharedapplication() { allow orientation = theappdelegate.statusbarorientation if orientation.isportrait { // portrait } else { // landscape } }
ios xcode ipad orientation swift
Comments
Post a Comment