PopOver frame issue in iPhone SDK

2019-08-30 15:37发布

I display a popover in map view as follows:

enter image description here

But when i rotate the device, It shows Like:

enter image description here

as you see it covers the annotation instead of showing just beside the annotation.

My code is as as shown below:

CGPoint annotationPoint = [mapView convertCoordinate:aView.annotation.coordinate toPointToView:mapView];
        float boxDY=annotationPoint.y;
        float boxDX=annotationPoint.x;
        CGRect box = CGRectMake(boxDX,boxDY,5,5);


        UILabel *displayLabel = [[UILabel alloc] initWithFrame:box];


         [popView presentPopoverFromRect:displayLabel.frame inView:mapView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


        [displayLabel release];

Help me to solve this problem.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-30 15:56

You can try to override the following method (declared in UIViewcontroller.h) :

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

You'll probably need to save the state of your viewController (like isPopoverPresented, which annotation etc.) and update the popover's rect accordingly.

查看更多
登录 后发表回答