Search code examples
objective-ccocoa-touchios4

Resize UIImageView in UITableViewCell upon rotation


I'm setting a UIImageView into my table cells during - (UITableViewCell *)tableView:(UITableView *)tableVw cellForRowAtIndexPath:(NSIndexPath *)indexPath

They are stretchable images (created with stretchableImageWithLeftCapWidth)

How can I update their size when my table view is rotated to another orientation?


Solution

  • First, create an IBOutlet for each object to be resized. Open interface builder and connect the outlets to your file's owner.

    You will need to override the method

    willAnimateFirstHalfOfRotationToInterfaceOrientation:duration

    This is for making changes that will happen before the roation animation is finished, or you could use

    willAnimateSecondHalfOfRotationToInterfaceOrientation:duration

    if you want the new positioning to occur at the same time the rotation finishes.

    Inside the animate method, you will redraw the frame depending on which orientation the phone is now in: Example:

    button1.frame = CGRectMake(20, 20, 125, 125);