ios - UIButton center position doesn't update with rotation -


i have program dynamically generates uibuttons in center of screen push of button. buttons not updating x-coordinates when rotate device.

here code creating buttons:

- (ibaction)createbutton:(uibutton *)sender {      uibutton *button = [uibutton buttonwithtype:uibuttontypecustom];        [button setbackgroundcolor:[uicolor redcolor]];     [button addtarget:self action:@selector(dosomething:) forcontrolevents:uicontroleventtouchupinside];      button.frame = cgrectmake(self.xcoord,self.yoffset,100.0,120.0);      [self.view addsubview:button];      _yoffset = _yoffset+130;      } 

the xcoord , self.yoffset set in viewdidload:

- (void)viewdidload {     [super viewdidload];      self.yoffset = 109;     self.xcoord = self.view.bounds.size.width/2-50;  } 

the coordinates of button in code fixed once they've been added view. if want update frame of buttons when screen rotates, you'll need trigger repositioning of buttons when screen rotates.

autolayout in storyboard makes easier (if want button appear can add in storyboard , change hidden property no yes when other button pressed -- won't helpful if want add arbitrary number of buttons, although have hidden placeholder view use positioning reference)


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -