iphone - How to get top left coordinate when the coordinate on circumference of circle is known? -


i have 2 concentric circles, distance between constant. obtain coordinate on circumference of outer circle based on angle obtained when touch in circular portion(including black circle inside).

this subclass of uicontrol , use touches method point on circumference.

i exact angle , hence exact point on circumference of outermost circle.

but want place button on top of concentric circle such diameter = distance_between_concentric_circles + 2 * offset.

this offset used button edges should come outside area of concentric circle. image below

enter image description here

and each time move button, should move along circular path.

since not want draw , m using uibutton , image view, , m finding hard top left co-ordinate based on point on circumference of outer circle , size of uibutton.

i can move button not correctly place on circular path.

can tell me if there way top left co-ordinate set frame of uibutton.

i want without drawing it.

any appreciated.

it's easier not worry top left corner, rather set center property (instead of frame property) of button. it's not hard calculate offset upper left, adjusting center property far more intuitive, imho.


alternatively, if don't want adjust center or frame coordinates, use quartz 2d rotate button point on screen:

  • change button's anchorpoint;

  • set position of button point rotating (and because , you've set anchorpoint, button appropriately offset position); and

  • rotate anchor point.

so, if link quartzcore.framework project, can then:

#import <quartzcore/quartzcore.h>  @interface viewcontroller ()  @property (nonatomic, strong) cadisplaylink *displaylink; @property (nonatomic) cftimeinterval starttime;  @end  @implementation viewcontroller  - (void)viewdidload {     [super viewdidload];      [self rotatebuttonaroundpoint]; }  - (void)rotatebuttonaroundpoint {     // point i'm rotating , @ radius      cgpoint center = cgpointmake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0);     cgfloat radius = 100.0;      // configure button's layer accordingly      self.button.layer.anchorpoint = cgpointmake(0.5, 0.5 + radius / self.button.frame.size.height);     self.button.layer.position = center;      // can see i'm rotating around      [self addcircleat:center radius:5.0 color:[uicolor redcolor]];      // turn on display link animate (better `nstimer` animations)      [self startdisplaylink]; }  - (void)addcircleat:(cgpoint)center radius:(cgfloat)radius color:(uicolor *)color {     cashapelayer *layer = [cashapelayer layer];     uibezierpath *path = [uibezierpath bezierpathwitharccenter:center radius:radius startangle:0 endangle:2.0 * m_pi clockwise:yes];      layer.path = [path cgpath];     layer.fillcolor = [color cgcolor];     [self.view.layer addsublayer:layer]; }  - (void)startdisplaylink {     self.displaylink = [cadisplaylink displaylinkwithtarget:self selector:@selector(handledisplaylink:)];     self.starttime = cacurrentmediatime();     [self.displaylink addtorunloop:[nsrunloop currentrunloop] formode:nsdefaultrunloopmode]; }  - (void)stopdisplaylink {     [self.displaylink invalidate];     self.displaylink = nil; }  - (void)handledisplaylink:(cadisplaylink *)displaylink {     cftimeinterval elapsed = cacurrentmediatime() - _starttime;      self.button.transform = cgaffinetransformmakerotation(elapsed * 2.0 * m_pi / 5.0); // duration = 5.0 seconds } 

i suspect changing center/frame or doing translation (rather rotation) might computationally less expensive, if want button rotate it's spinning around, option, , enjoys elegance (just set position , anchorpoint , rotate that, not worrying cartesian coordinates @ all).


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -