UITableView correcting scroll position after device rotation

后端 未结 6 812
予麋鹿
予麋鹿 2021-01-03 13:45

I\'m building something like a reader for a book. When the user rotates the phone I want to increase the font size. I\'m using a UITableView to display chunks o

6条回答
  •  情歌与酒
    2021-01-03 13:56

    Firstly, to reload all of your table cells use [self.tableView reloadData]

    Secondly, add the line of code that is responsible for the shrinking inside the (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method.

    Example:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //Some identifier and recycling stuff
    
    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
        //Make labels smaller
    }
    else {
        //Make them bigger
    }
    }
    

    Or you can just call your updateCellForRotate:forRow: method when making them. But I'm not sure how that function works, so I can't be too specific.

提交回复
热议问题