I am building an app where there is a game board in the middle, and on one side there is a side view for each player showing a picture and the player's name. I'd like that name to be oriented 90 degrees, so it is legible from either side of the board:
I had this mostly working while targeting iOS7 by subclassing UIView as PlayerNameView, with its own xib which I am instantiating in code in viewDidLoad. This class itself is using Auto Layout, so whatever space it is put in, it can automatically adjust its own size.
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"PlayerNameView" owner:nil options:nil];
self.landscapeWhiteNameView = [nibContents lastObject];
[self.view addSubview:self.landscapeWhiteNameView];
self.landscapeWhiteNameView.translatesAutoresizingMaskIntoConstraints = NO;
And then I would simply rotate the view:
self.landscapeWhiteNameView.transform = CGAffineTransformMakeRotation(M_PI_2);
I did all of the interface layout using Auto Layout in code in updateViewConstraints.
This all worked fairly well, but since then I've decided to have a go at using iOS8, size classes, and doing all of my Auto Layout using Interface Builder.
The problem is that rotated view doesn't seem to play nice with Auto Layout. It seems that the layout constraints are 90 degrees off, and the layout just doesn't seem possible using IB alone. The problem between Auto Layout and transforms is nicely summarized in this post:
How do I adjust the anchor point of a CALayer, when Auto Layout is being used?
I'm trying to come up with some way to do this as cleanly as possible. All of the possibilities I have come up with have failed for one reason or another. What I am left with is the idea of creating a method which will take as input a player's name and image and output a UIImage showing, effectively, that PlayerNameView rendered to UIImage.
It seems like I'll lose a number of benefits I'm trying to gain by targeting iOS8, such as Dynamic Type. I also don't know how to get away from doing a bunch of fidgety hand layout for this view instead of being able to rely on Auto Layout to render my text and image at the appropriate size.
Am I missing a more elegant way to do this? Again, my goals:
iOS8, utilizing Size Classes to only have to do one storyboard for iPad and iPhone
Auto Layout fully in Interface Builder
Text rotated 90 degrees