views:

51

answers:

2

I've learned that the best way to get graceful rotation is to set the auto rotation mask on the view that you want resize or move. This works fine if you're using SDK views like UILabel, but if you have your own custom view that uses the drawRect method it doesn't rotate as gracefully. In fact the only thing that happens is that it stretches whatever you drew in drawRect.

I've tried redrawing both before and after the rotation, but it doesn't give me that smooth rotation.

I looked at a UITextField auto rotating (flexible width) in slow motion and it follows the edge perfectly during the rotation. That is what I want my view to do, so how do I do that? My views jump to the right position either before or after the rotation.

A: 

I would guess that the UITextField you're looking at has at least three subviews, one displaying the left cap of the field's border, one displaying the right cap, and one displaying the middle, with autoresizing masks of "flexible right margin", "flexible left margin", and "flexible width", respectively. If you set up your custom view something like that, and make sure its autoresizesSubviews property is set to YES, then you should get the same smooth resize that the text field does.

Noah Witherspoon
Not exactly the answer I was expecting and not exactly the answer I was hoping for, but this being said I think your solution would work just fine. :) I have one problem with it though. I have a stretchable UIImage that I'm drawing in the view's rect and I can't easily make that UIImage three subviews. Also I don't think that I can accept this as my answer as restructuring your views to use subviews instead of drawRect was a solution that I was very well aware of.
Erik B
A: 

The following line will make your UIView stretch the middle pixel only. If this is not your desired behavior I suggest you read the documentation for contentStretch to learn how to manipulate the values of the CGRect.

[self setContentStretch:CGRectMake(0.5, 0.5, 0.0, 0.0)];
Erik B