objective c - iOS change height for orientation -


i've got conditional float in loadview method, works fine 2 devices. however, i've had worst time trying find way make these change orientation.

i have in prefix.pch:

#define ddeviceorientation [[uidevice currentdevice] orientation] #define isportrait  uideviceorientationisportrait(ddeviceorientation) #define islandscape uideviceorientationislandscape(ddeviceorientation) #define isfaceup    ddeviceorientation == uideviceorientationfaceup   ? yes : no #define isfacedown  ddeviceorientation == uideviceorientationfacedown ? yes : no 

i have in loadview method (portrait because want know works first...:

cgrect screenbounds = [[uiscreen mainscreen] bounds]; cgfloat screenheight = cgrectgetheight(screenbounds);           float y; if ((ui_user_interface_idiom() == uiuserinterfaceidiompad)){             nslog(@"%f", screenheight);     if (isportrait){  y = (screenheight-(0.14*screenheight));     }else{      } } else {     if (isportrait){         y = (screenheight-(0.25*screenheight));     }else{                 } } settingsbutton.frame = cgrectmake(20, y, 40, 40.0); aboutbutton.frame = cgrectmake(75, y, 40, 40.0); 

there many solutions out there, not sharp.

=====

matt neuburg guided me consider nslayoutconstraint... mustered:

[self.view addsubview:ab]; [self.view addsubview:sb]; //constraints nslayoutconstraint *constraint =[nslayoutconstraint                                   constraintwithitem:ab                                 //ab's relation left edge                                   attribute:nslayoutattributeleading                                                                         relatedby:nslayoutrelationequal                                   toitem:self.view                                   attribute:nslayoutattributeleading                                                                         multiplier:1.0f                                   constant:7.f]; [self.view addconstraint:constraint];  constraint = [nslayoutconstraint               constraintwithitem:ab               //ab's relation bottom edge               attribute:nslayoutattributebottom               relatedby:nslayoutrelationequal               toitem:self.view               attribute:nslayoutattributebottom               multiplier:1.0f               constant:-10.f];  [self.view addconstraint:constraint];  constraint = [nslayoutconstraint constraintwithitem:sb             //sb's identical relation bottom edge ( violation of dry i'm in hurry :'( //               attribute:nslayoutattributebottom               relatedby:nslayoutrelationequal               toitem:self.view attribute:nslayoutattributebottom               multiplier:1.0f constant:-10.f]; [self.view addconstraint:constraint];  constraint = [nslayoutconstraint               //sb's relation leading edge               constraintwithitem:sb               attribute:nslayoutattributeleading               relatedby:nslayoutrelationequal               toitem:self.view               attribute:nslayoutattributeleading               multiplier:1.0f               constant:75.0f]; [self.view addconstraint:constraint]; 

and result:

enter image description here

enter image description here

as others have implied, problem viewdidload way soon. give bunch of solutions in book:

http://www.apeth.com/iosbook/ch19.html#secrotationevents

viewdidlayoutsubviews excellent place. best of in ios 6 give constraints , don't need code on rotation @ all.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -