ios - Scale circle uivew just big enough to fill screen -


i automate scale factor of many uiviews have cornerradius set circles. idea these 20 circle uiviews, of varying sizes , location, scale fill screen no matter size, location etc when tapped.

my code has hard coded value make intelligent:

[uiview animatewithduration:0.2 delay:0.0 options:uiviewanimationoptioncurveeaseinout animations:^{     self.layer.affinetransform = cgaffinetransformmakescale(15.0f, 15.0f);  } completion:^(bool finished) { }]; 

yes - type in 20 cgaffinetransformmakescale bigger circles scaling larger no reason - might need scale 11 instead.

what way factor original size fixed, larger size?

note: circle uiview, being rounded, should scale big enough rounded edges not visible - needs scale beyond screen fill in gaps @ corners.

conceptually, want center circle in screen, scale screen rect inscribed in circle. here's handy diagram:

inscribed rect

from center of screen, can draw triangle corner. hypotenuse of triangle desired circle radius. here's code transform circle:

[uiview animatewithduration:0.2 animations:^{      cgpoint screencenter = cgpointmake(cgrectgetmidx([uiscreen mainscreen].bounds), cgrectgetmidy([uiscreen mainscreen].bounds));     cgpoint circlecenter = [self.window convertpoint:self.center fromview:self.superview];      // calculate distance circle's current center screen center     uioffset offset = uioffsetmake(screencenter.x - circlecenter.x, screencenter.y - circlecenter.y);      // calculate distance screen center corner     cgfloat screenradius = sqrtf(powf(cgrectgetwidth([uiscreen mainscreen].bounds) * 0.5, 2.0f)                                  + powf(cgrectgetheight([uiscreen mainscreen].bounds) * 0.5, 2.0f));     cgfloat circleradius = cgrectgetwidth(self.bounds) * 0.5;      cgfloat scale = screenradius / circleradius;      // combine scale , translation     cgaffinetransform scaletransform = cgaffinetransformmakescale(scale, scale);     cgaffinetransform translatetransform = cgaffinetransformmaketranslation(offset.horizontal, offset.vertical);     self.transform = cgaffinetransformconcat(scaletransform, translatetransform); }]; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -