Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table view that lists board positions is incorrectly sized after interface orientation change #236

Closed
herzbube opened this issue Aug 8, 2014 · 2 comments

Comments

Projects
None yet
1 participant
@herzbube
Copy link
Owner

commented Aug 8, 2014

  1. Launch the app in Portrait orientation
  2. Rotate to Landscape
  3. Scroll down to the bottom of the table view that lists board positions

Expected: All board positions are visible
Actual: Some board positions are not visible; it appears that the table view is still sized for Portrait

@herzbube herzbube added this to the 1.1.0 milestone Aug 8, 2014

@herzbube herzbube added bug labels Aug 8, 2014

@herzbube herzbube self-assigned this Aug 8, 2014

@herzbube

This comment has been minimized.

Copy link
Owner Author

commented Aug 8, 2014

This issue is not present in 1.0.0 or older versions. This issue is a result of adding Auto Layout and iOS 7 support.

After several hours of troubleshooting and reducing the problem to a minimal code example that still exhibits the problem, the culprit that performs the incorrect resize was identified as UISplitViewController.

@herzbube

This comment has been minimized.

Copy link
Owner Author

commented Aug 8, 2014

Minimal code example.

  1. Copy & paste into an empty Xcode project
  2. Run the example according to the steps to reproduce in the issue description
  3. The blue view on the left can be seen to extend behind the tab bar at the bottom of the screen

left-pane-extends-behind-tabbar

#pragma mark Interface declarations

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow* window;
@end

@interface SubViewController : UIViewController
@end

@interface LeftPaneViewController : UIViewController
@property (strong, nonatomic) SubViewController* subViewController;
@end

@interface RightPaneViewController : UIViewController
@end


void installAutoLayoutConstraints(UIView* superview, UIView* subview);

#pragma mark Implementation AppDelegate

@implementation AppDelegate

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
  UISplitViewController* svc = [[UISplitViewController alloc] initWithNibName:nil bundle:nil];
  UIViewController* leftPaneViewController = [[LeftPaneViewController alloc] init];
  UIViewController* rightPaneViewController = [[RightPaneViewController alloc] init];
  svc.viewControllers = [NSArray arrayWithObjects:leftPaneViewController, rightPaneViewController, nil];
  svc.edgesForExtendedLayout = UIRectEdgeNone;
  svc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"foo" image:nil tag:0];

  UITabBarController* tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
  tbc.viewControllers = [NSArray arrayWithObject:svc];

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  self.window.rootViewController = tbc;
  self.window.backgroundColor = [UIColor whiteColor];
  [self.window makeKeyAndVisible];

  return YES;
}

@end

#pragma mark Implementation LeftPaneViewController

@implementation LeftPaneViewController
- (void) loadView
{
  [super loadView];
  self.view.backgroundColor = [UIColor yellowColor];

  self.subViewController = [[SubViewController alloc] initWithNibName:nil bundle:nil];
  [self addChildViewController:self.subViewController];
  [self.subViewController didMoveToParentViewController:self];
  [self.view addSubview:self.subViewController.view];

  installAutoLayoutConstraints(self.view, self.subViewController.view);
}
@end

#pragma mark Implementation RightPaneViewController

@implementation RightPaneViewController
- (void) loadView
{
  [super loadView];
  self.view.backgroundColor = [UIColor magentaColor];
}
@end

#pragma mark Implementation SubViewController

@implementation SubViewController
- (void) loadView
{
  [super loadView];
  self.view.backgroundColor = [UIColor greenColor];

  UIView* v = [[UIView alloc] initWithFrame:CGRectZero];
  v.backgroundColor = [UIColor blueColor];
  [self.view addSubview:v];

  installAutoLayoutConstraints(self.view, v);
}
@end

#pragma mark Implementation installAutoLayoutConstraints

void installAutoLayoutConstraints(UIView* superview, UIView* subview)
{
  subview.translatesAutoresizingMaskIntoConstraints = NO;
  NSDictionary* viewsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                   subview, @"subview",
                                   nil];
  NSArray* visualFormats = [NSArray arrayWithObjects:
                            @"H:|-0-[subview]-0-|",
                            @"V:|-0-[subview]-0-|",
                            nil];
  for (NSString* visualFormat in visualFormats)
  {
    NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:visualFormat
                                                                   options:0
                                                                   metrics:nil
                                                                     views:viewsDictionary];
    [superview addConstraints:constraints];
  }
}

@herzbube herzbube closed this in 202a397 Aug 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.