How to avoid text disappearing when using CGAffineTransform?
I want to make a button rotate in my app, and I have the following piece of code:
- (void)setFrameForButton:(UIButton *)ok {
if ([[UIDevice currentDevice] isWildcat]) {
if([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
ok.frame = CGRectMake(244, 840, 280, 20);
if (wasChanging) ok.transform = CGAffineTransformMakeRotation(M_PI * -0.50);
}
else {
ok.frame = CGRectMake(372, 584, 280, 20);
if (wasChanging) ok.transform = CGAffineTransformMakeRotation(M_PI * -0.50);
}
}
else {
ok.frame = CGRectMake(15.0, 375.0 ,2开发者_开发百科80.0, 20.0);
}
if (wasChanging) wasChanging = NO;
}
- (void)window:(id)window willRotateToInterfaceOrientation:(int)orientation duration:(double)duration {
wasChanging = YES;
[self setFrameForButton:btn];
}
Although when I rotate the position it should be is changed and after some following rotations the text at my button disappears. What to do?
Not sure whether this is the issue, but try setting the autoresizesSubviews
property of yor UIButton
to NO
. This might stop the UIButton
from trying to transform its text in any weird way and mess it up.
精彩评论