iosobjective-clayoutautoresizingmaskcontentmode

How to do a custom layout of a UIView so it works with both iPhone 5 screen dimensions as well as regular screen dimensions


Here is the desired outcome. The blue area is the UIView of interest. The UIView is not a UIImageView.

enter image description here

I've tried all sorts of arrangements with auto-resizing masks to no avail


Solution

  • This can only be done programmatically. One option is what @user2223761 suggests with subclassing. If you don't want to subclass UIView, then you need to set the frames on orientation changes and set yourView.center to be the center of the center.

    - (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    
       if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
              // Make sure that the frame is centered in the screen
              NSInteger paddingLeftSide = (self.view.bounds.size.width - 480) / 2;
              self.view.frame = CGRectMake(paddingLeftSide, 0, 480, 320);   
          } else {
              self.view.frame = CGRectMake(0, 0, 320, 320);
          }
      }