Question

I have a view which should have a different layout in portrait and Landscape mode. I implement a method to redraw my UI elements with Autosizing (no AutoLayout):

-(void)buildViewElements:(UIInterfaceOrientationMask)interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationMaskPortrait) {
    NSLog(@"Portrait");

    [UIView animateWithDuration:duration animations:^{
        CGRect newImageFrame = CGRectMake(20, 15, 100, 100);
        _personImage.frame   = newImageFrame;
        CGRect newNameLabelFrame = CGRectMake(128, 20, 172, 21);
        _nameLabel.frame = newNameLabelFrame;
        CGRect newNameDescFrame = CGRectMake(128, 41, 172, 21);
        _nameDescriptionLabel.frame = newNameDescFrame;
        CGRect newBorrowedFrame = CGRectMake(128, 64, 75, 21);
        _borrowedLabel.frame = newBorrowedFrame;
        CGRect newBorrowedValueFrame = CGRectMake(211, 64, 42, 21);
        _borrowedValueLabel.frame = newBorrowedValueFrame;
        CGRect newLendFrame = CGRectMake(128, 93, 75, 21);
        _lendLabel.frame = newLendFrame;
        CGRect newLendValueFrame = CGRectMake(211, 93, 42, 21);
        _lendValueLabel.frame = newLendValueFrame;

        CGRect newcontainerFrame = CGRectMake(0, 130, 320, [CNX_Tools getLargestAttributeOfSize:[[UIScreen mainScreen] bounds].size] - 194);
        _tableContainerView.frame = newcontainerFrame;
        CGRect newDetailFrame = CGRectMake(20, 0, 280, 29);
        _detailSelector.frame = newDetailFrame;
        CGRect newTableFrame = CGRectMake(0, 36, 320, newcontainerFrame.size.height - 39);
        _tableView.frame = newTableFrame;
    }];
}
else if (interfaceOrientation == UIInterfaceOrientationMaskLandscape) {
    NSLog(@"Landscape");

    [UIView animateWithDuration:duration animations:^{
        CGFloat factor = 1.0f;
        CGFloat diff   = 0.0f;
        if ([CNX_Tools getLargestAttributeOfSize:[[UIScreen mainScreen] bounds].size] <= 480) {
            // iPhone4 size
            factor =  0.8f;
            diff   = 10.0f;
        }

        CGRect newImageFrame = CGRectMake(75*factor-diff, 20, 100, 100);
        _personImage.frame = newImageFrame;
        NSLog(@"Bild Frame %f", newImageFrame.origin.x);
        CGRect newNameLabelFrame = CGRectMake(20, 140, 210*factor, 21);
        _nameLabel.frame = newNameLabelFrame;
        CGRect newNameDescFrame = CGRectMake(20, 161, 210*factor, 21);
        _nameDescriptionLabel.frame = newNameDescFrame;
        CGRect newBorrowedFrame = CGRectMake(20, 184, 75, 21);
        _borrowedLabel.frame = newBorrowedFrame;
        CGRect newBorrowedValueFrame = CGRectMake(103, 184, 42, 21);
        _borrowedValueLabel.frame = newBorrowedValueFrame;
        CGRect newLendFrame = CGRectMake(20, 213, 75, 21);
        _lendLabel.frame = newLendFrame;
        CGRect newLendValueFrame = CGRectMake(103, 213, 42, 21);
        _lendValueLabel.frame = newLendValueFrame;

        CGRect newContainerFrame = CGRectMake(250*factor, 0, [CNX_Tools getLargestAttributeOfSize:[[UIScreen mainScreen] bounds].size] - 250*factor, 268);
        _tableContainerView.frame = newContainerFrame;
        CGRect newDetailFrame = CGRectMake(20, 10, newContainerFrame.size.width - 40 , 29);
        _detailSelector.frame = newDetailFrame;
        CGRect newTableFrame = CGRectMake(0, 49, newContainerFrame.size.width, 219);
        _tableView.frame = newTableFrame;
    }];
}

}

This method is called from method:

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

switch (toInterfaceOrientation) {
    case UIInterfaceOrientationPortrait:
        [self buildViewElements:UIInterfaceOrientationMaskPortrait duration:duration];
        break;
    case UIInterfaceOrientationPortraitUpsideDown:
        [self buildViewElements:UIInterfaceOrientationMaskPortrait duration:duration];
        break;
    case UIInterfaceOrientationLandscapeLeft:
        [self buildViewElements:UIInterfaceOrientationMaskLandscape duration:duration];
        break;
    case UIInterfaceOrientationLandscapeRight:
        [self buildViewElements:UIInterfaceOrientationMaskLandscape duration:duration];
        break;
    default:
        break;
}

}

The method getLargestAttributeOfSize: returns the largest size attribute (height or width).

If I start the view in portrait I can tapp an the table cells and method tableView: didSelectRowAtIndexPath: is called. After a rotation to landscape mode all cells are not selectable and I cannot scroll in the table. But, if I leaf this screen and call ist again (in landscape mode), the same table cells are selectable, the method is called and I can stroll trough the table. If I rotate the device to portrait, I have the same faulty behavior. After a rotation of my device I can not interact with my table and its cells.

Can someone help me please or have an idea what's my issue here? Thanks!

Was it helpful?

Solution

My guess is that a superview of your UITableView is not adjusted correctly. The input can than never reach your UITableView, but when it is started fresh all is well. Probably the view of your UIViewController.

Try setting clipsToBounds:YES to the superviews to see if your tableView is actually out of the views bounds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top