-1

我试图改变横向的 UIlabels 坐标,所以我这样做了。问题是它不起作用。我究竟做错了什么?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
if (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) {
    label.frame = CGRectMake(377, 15, 42, 21); 
     }
}
4

1 回答 1

0

仔细看看你的代码:

- (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。

于 2012-06-22T16:13:37.637 回答