iphone - The X and Y coordinates of the right callout button are not placing my views accurately -


as can see below using calloutaccessorycontrol's coordinates place view on mapview. however. never seems place control anywhere near calloutaccessorycontrol. strange, because using x , y coordinates.

- (void)mapview:(mkmapview *)mapview annotationview:(mkannotationview *)view                        calloutaccessorycontroltapped:(uicontrol *)control {     hotelinformationviewcontroller *vc =      [[hotelinformationviewcontroller alloc]initwithnibname:@"hotelinformationviewcontroller"      bundle:nil control:control];      [self.view addsubview:vc.view]; }  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil control:(uicontrol *)control {   if ((self = [super initwithnibname:nibnameornil bundle:nibbundleornil]))    {     self.view.bounds = cgrectmake(control.frame.origin.x, control.frame.origin.y, 286, 286); //as can see here using x , y place new control   }   return self; } 

you need set frame instead of bounds.

but other problem callout button's position relative popup view of annotation (not self.view). annotation's popup position relative map view, etc.

you need convert callout's position self.view's coordinate system using convertpoint:toview: method.

modify init method follows:

- (id)initwithnibname:(nsstring *)nibnameornil                 bundle:(nsbundle *)nibbundleornil                control:(uicontrol *)control             withparent:(uiview *)parentview {     if ((self = [super initwithnibname:nibnameornil bundle:nibbundleornil]))      {         cgpoint calloutorigininparent =              [control convertpoint:control.bounds.origin toview:parentview];          cgrect myframe;         myframe.origin.x =              calloutorigininparent.x + control.frame.size.width + 5;         myframe.origin.y = calloutorigininparent.y;         myframe.size.width = 286;         myframe.size.height = 286;         self.view.frame = myframe;     }     return self; } 

in init method above, you'll have adjust hotel view's frame doesn't show off screen happen if callout near right or bottom edge of screen.

then in calloutaccessorycontroltapped method:

hotelinformationviewcontroller *vc = [[hotelinformationviewcontroller alloc]      initwithnibname:@"hotelinformationviewcontroller"      bundle:nil      control:control      withparent:self.view];  [self.view addsubview:vc.view];  [vc release]; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -