Correct rotation of a UITableView using Transform without interacting with Interface Builder

UiTableView does not provide horizontal scrolling in landscape mode.

My UiTableView is not fullscreen (so I can’t just use it horizontally when rotating my content, which is an image)

I found that in order to rotate my UiTableView using Transforms, I had to place it in the Interface Builder in some strange position so that it would look right when rotated .....

Has anyone done this without mess with Interface Builder? The same code?

+3
source share
4 answers

, , , , ( ). UITableView layoutSubviews, :

- (void)layoutSubviews {

    [super layoutSubviews];

    for (UIView* child in [self subviews]) {

        CGRect frame1 = child.frame;
        if ([child isKindOfClass:[UITableViewCell class]]) {
            frame1.size.width = 120;
            child.frame = frame1;        
        } 
    }

}
+4

" " Windows Views Apple. , Interface Builder .

, . shouldAutorotateToInterfaceOrientation:interfaceOrientation, willRotateToInterfaceOrientation:duration: didRotateFromInterfaceOrientation: UIViewController, , , , , .

Edit

Apple:

UITableView UIScrollView, . UITableView .

, Apple , . , , UITableView, , , . , , , . , , .

, Apple , , , HIG.

+3

, , :

  • UITableView UIViewController , IB ( UITableViewController)
  • 90 .
  • tableView: cellForRowAtIndexPath: 90 , .

Boum! . , , , , .

: . anchorPoint ( CGPoint). , , ( ) .

+1

I know this a bit later, but here is my answer.

As others have said, to achieve horizontal scrolling, you can apply a 90 degree transform to the scoreboard. But in order to get rid of a strange frame error, you must get the frame before the conversion, apply the conversion, and then restore the frame to the original one.



// Save the tableview frame (as it is layed out in IB)
CGRect oldframe = tableview.frame;

// Apply the transform
tableview.transform=CGAffineTransformMakeRotation(M_PI/2);

// For some weird reason, the frame of the table also gets rotated, so you must restore the
//original frame    
tableview.frame = oldframe;


0
source

Source: https://habr.com/ru/post/1708521/


All Articles