objective c - mainScreen bounds size differs on iOS 7 vs iOS 8 upon calling willRotateToInterfaceOrientation -



objective c - mainScreen bounds size differs on iOS 7 vs iOS 8 upon calling willRotateToInterfaceOrientation -

i know ios 8 returns proper screen dimensions current interface orientation. device width orientation in ios 7 had homecoming height if orientation landscape or width if orientation portrait, can homecoming width in ios 8. have taken consideration app i'm developing back upwards ios 7 , 8. (see code below)

however, noticed difference. if phone call method , pass in orientation (obtained willrotatetointerfaceorientation), on ios 7 homecoming proper width on ios 8 returns width old (current) orientation.

how can width of screen when know orientation or on ios 8 , ios 7?

while swap width , height ios 8, homecoming wrong value when function called while device isn't transitioning new orientation. create 2 different methods i'm looking cleaner solution.

- (cgfloat)screenwidthfororientation:(uiinterfaceorientation)orientation { nsstring *reqsysver = @"8.0"; nsstring *currsysver = [[uidevice currentdevice] systemversion]; if ([currsysver compare:reqsysver options:nsnumericsearch] != nsorderedascending) { homecoming [uiscreen mainscreen].bounds.size.width; } cgrect screenbounds = [uiscreen mainscreen].bounds; cgfloat width = cgrectgetwidth(screenbounds); cgfloat height = cgrectgetheight(screenbounds); if (uiinterfaceorientationisportrait(orientation)) { homecoming width; } else if (uiinterfaceorientationislandscape(orientation)) { homecoming height; } homecoming width; }

use cases:

ipad running ios 7:

calling [self screenwidthfororientation:[uiapplication sharedapplication].statusbarorientation] in viewdidappear returns right width calling [self screenwidthfororientation:tointerfaceorientation] in willrotatetointerfaceorientation:tointerfaceorientation:duration returns right width

ipad running ios 8:

calling [self screenwidthfororientation:[uiapplication sharedapplication].statusbarorientation] in viewdidappear returns right width calling [self screenwidthfororientation:tointerfaceorientation] in willrotatetointerfaceorientation:tointerfaceorientation:duration returns wrong width (what before rotation occurs)

here code calculate right width , height ios7 / ios8 before applying constraints.

- (void) applyconstraints:(uiinterfaceorientation)tointerfaceorientation { cgsize screensize = [[uiscreen mainscreen] bounds].size; cgfloat heightofscreen; cgfloat widthofscreen; if (system_version_greater_than_or_equal_to(@"8.0")) { // ios 8.0 , later code here if ([uiapplication sharedapplication].statusbarorientation == tointerfaceorientation) { heightofscreen = screensize.height; widthofscreen = screensize.width; } else { heightofscreen = screensize.width; widthofscreen = screensize.height; } } else { if (uideviceorientationislandscape(tointerfaceorientation)) { heightofscreen = screensize.width; widthofscreen = screensize.height; } else { heightofscreen = screensize.height; widthofscreen = screensize.width; } } //applying new constraints ... }

it not beautiful works =)

ios objective-c ios7 rotation ios8

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -