仔细看看你的代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// this line returns immediately
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
// and this code never ever hits...
if (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) {
label.frame = CGRectMake(377, 15, 42, 21);
}
// nor does it return anything (it's supposed to return a BOOL)
}
尝试这样做:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) {
if(label)
{
label.frame = CGRectMake(377, 15, 42, 21);
} else {
NSLog( @"label is nil; why is that?" );
}
}
// return a BOOL to tell the view controller to rotate in all cases
return YES;
}
我没有测试此代码的正确性,据我所知,唯一发生的事情是标签框架将在除两种横向模式之一 之外的所有情况下重置为该 CGRect。