Search code examples
objective-cxcodeinterface-builderstoryboarduiinterfaceorientation

Xcode view doesn't handle click events after changing orientation


I found the question for Android, but could not find it for Xcode so I created a new question.

I have a VC which has three subviews. in landscape mode -> image view (left), image-details view (center) and related items tableview on the right. In portrait mode the image view remains in the top left corner and image details on the top right, but the related tableview goes below image view. I am handling rotation by following code.

 - (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
  CGRect detailsFrame = self.detailsView.frame;
  CGRect relatedFrame = self.relatedView.frame;
  if (UIInterfaceOrientationIsLandscape(orientation)) {
    detailsFrame.origin.x = 300.0f;
    detailsFrame.origin.y = 69.0f;
    relatedFrame.origin.x = 709.0f;
    relatedFrame.origin.y = 20.0f;
} else {
    detailsFrame.origin.x = 330.0f;
    detailsFrame.origin.y = 50.0f;
    relatedFrame.origin.x = 10.0f;
    relatedFrame.origin.y = 400.0f;
}
self.detailsView.frame = detailsFrame;
self.relatedView.frame = relatedFrame;
 }

Now my issue is that I can click a table cell or image view in landscape mode, but cannot click the tableview cell in portrait mode. I have spent enough time figuring out what could be wrong, but could not find any solution.


Solution

  • Orientation is also handled in xib instead of the code. So please set the proper autoresizing masks in interface builder. Please see the diagram for better understanding.

    autoresizing masks
    If you have doubt then please ask me.