iphone - UIOrientation returns 0 or 5 -
i running simple function get's called in multiple areas deal layout on ipad app during orientation changes. looks this:
- (void) getwidthandheightfororientation:(uiinterfaceorientation)orientation { nslog(@"new orientation: %d",orientation); end
and call in various places this:
[self getwidthandheightfororientation: [[uidevice currentdevice] orientation]];
the function has simple code runs if orientation portrait or landscape. unfortunately wasn't working expected when app started in position 1. 0 result. later if function called in same manner device has never been rotated value of 5. mean? why throw these values?
in short why [[uidevice currentdevice] orientation] ever throw 0 or 5 instead of value between 1 , 4?
update:
because kept finding bugs in code due way orientation handled, wrote definitive post on how handle uidevice or uiinterface orientations: http://www.donttrustthisguy.com/orientating-yourself-in-ios
i recommend using uideviceorientationisvalidinterfaceorientation(orientation)
it tell if valid orientation (valid being either landscape or portrait, not faceup/facedown/unknown). can treat if portrait if unknown.
this how it:
if (uideviceorientationisvalidinterfaceorientation(interfaceorientation) && uiinterfaceorientationislandscape(interfaceorientation)) { // handle landscape } else { // handle portrait }
Comments
Post a Comment