1

I have

  • a view controller named MyMapViewController which is the delegate of the map view that is in the storyboard,
  • a view controller (i.e. a container view, 'myContainerView', in the storyboard) named MyListViewController that is the child view controller of MyMapViewController.

So, I have the following in the storyboard: http://pasteboard.co/1YAmM2ZU.png

In MyMapViewController, I set myContainerView's frame initially as follows so that the only part shown would be its navigation bar at the bottom of MyMapViewController:

CGRect destFrame = self.myContainerView.frame;
CGFloat navBarHeight = 44;
destFrame.origin.y = self.view.frame.size.height - navBarHeight;//to bottom of the screen; navigation bar yields 44 points

[UIView animateWithDuration:0
                     animations:^{
                         self.myContainerView.frame = destFrame;
                     }
     ];

In MyMapViewController, I set some annotations on the map and the delegate method is as follows:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

     NSLog(@"welcome into the map view annotation");


     // if it's the user location, just return nil.
     if ([annotation isKindOfClass:[MKUserLocation class]])
         return nil;

     // try to dequeue an existing pin view first
     static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
     MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc]
                                     initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
     pinView.animatesDrop=YES;
     pinView.canShowCallout=YES;
     pinView.pinColor=MKPinAnnotationColorPurple;


     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     [rightButton setTitle:annotation.title forState:UIControlStateNormal];
     [rightButton addTarget:self
                  action:@selector(showDetails:)
                  forControlEvents:UIControlEventTouchUpInside];
     pinView.rightCalloutAccessoryView = rightButton;

     UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"annotationProfile.png"]];
     pinView.leftCalloutAccessoryView = profileIconView;

     return pinView;
}

The problem is that when I scroll the map to user's own location or to the location of an annotation that is not initially shown on the map or click on one of the annotations, myContainerView shows up suddenly. (it moves back to the place set in the storyboard.) However, I want myContainerView to stay where it was.

I came up with some possible explanations why it happens but am not quite sure how I can overcome this problem. Any suggestions?

Thanks in advance.

Burak
  • 525
  • 4
  • 24

1 Answers1

1

When you face a user interface abnormality such as the one in the question, then there is surely something you miss about the design. If this is the case, check if you solve the problem by manipulating the constraints you defined in the storyboard. You can bring the constraint into the code just by pressing ctrl and dragging it in your code and thus create a property. Then you can easily change the constraint's constant value in your code, for example for moving the related view to where you want in superview.

If this would not work, try implementing another UI design approach. For instance, you could create a .xib file for the view. This way, you can easily manipulate every single move of your view inside its superview just by changing its frame inside the superview. This approach gives you a much more elasticity than the one that in storyboard, but harder to implement.

Burak
  • 525
  • 4
  • 24