UILabel风景取向
问题描述:
我试图改变风景orient的UIlabels坐标,所以我做到了。问题是它不起作用。我究竟做错了什么?UILabel风景取向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
if (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) {
label.frame = CGRectMake(377, 15, 42, 21);
}
}
答
看看你的代码密切:
- (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;
}
我没有测试的正确性验证码,并从我可以告诉发生的唯一情况是,标签框架将重置为中的每个案例除两种景观模式之一。
当你说“*它不工作*”,我们不知道发生了什么!你需要告诉我们。我怀疑是你应该在'if ...'之前有方法中的return语句* last *。 – Ashe