Take the 2-minute tour ×

I am writing a MonoTouch iOS application.

I have a group of 4 UIButtons on my main View. They are more or less in a horizontal row. I want to rotate them by an angle (between -90 and +90 degrees) as a group with the right most button being the "anchor" for the group of buttons.

I can't figure out how to do this.

One thing I tried was I put these buttons inside of a UIView and then set the Transform to a CGAffineTransform.MakeRotation, but it rotates around the center of the UIView. I also tried making this parent UIView be wider than it needed to be so that the right most button in the group was in the center of the UIView. This worked for the rotation, but then the large blank section that was the right half of the parent UIView covers up other buttons that are on my main View that I need to be visible.

So my question is how do rotate UIButtons of a UIView where the rotation is around a point that is NOT the center of the UIButton or UIView?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can change the AnchorPoint of the view's layer, along with the Position to compensate for the shift due to setting the AnchorPoint. For example, say you had a view named ButtonGroup containing the buttons. The following code would rotate them 90 degrees about the lower left corner of the view:

ButtonGroup.Layer.Position = new PointF(ButtonGroup.Frame.Left, ButtonGroup.Frame.Bottom);
ButtonGroup.Layer.AnchorPoint = new PointF (0,1);            
ButtonGroup.Layer.AffineTransform = CGAffineTransform.MakeRotation((float)Math.PI/-2);
share|improve this answer
Sweet. Thank you! –  user856232 Apr 29 '12 at 1:12
add comment

Your Answer


