Greg Cawthorne
Greg Cawthorne

Reputation: 416

How to rotate UIButtons 90 degrees, without Auto Layout error?

I have a few UIButtons in an outlet collection array which I wish to rotate with this code:

for(UIButton *button1 in b90){
    button1.transform = CGAffineTransformMakeRotation( ( 90 * M_PI ) / 180 );
}

Unfortunately it doesn't work. It does work if I give it values which will rotate it 180 or 360 degrees e.g. pi or 2 pi etc. (basically meaning the button will be in the same place), but if i give it any other values that will leave the button at a skewed orientation I get this error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Autolayout doesn't support crossing rotational bounds transforms with edge layout constraints, such as right, left, top, bottom. The offending view is: >'

The frame and transform parts are self explanatory. I think it just is saying it doesn't want the buttons to be skewed at all. I can avoid the problem by dechecking the 'Use Autolayout' button in the xib file, but that makes the rotated buttons look pixelated. The unpixelated if you rotate the iDevice in run time, then rotate it back for some reason, but this isn't what i want.

Any ideas as to how to orate the buttons and not disable the 'Use Autolayout' option?

All help is greatly appreciated and i always check the best answer!

Upvotes: 4

Views: 3164

Answers (1)

Hindu
Hindu

Reputation: 2924

I am using same statement and it works for me:

#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)
btn.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-90));

I think you are using IOS 6.0 code, in which auto layout is enable with old xcode.

Can you provide more detail about it?

thanks

Upvotes: 4

Related Questions