简体   繁体   中英

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 ,280.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM