UILabel景观定位

时间:2012-06-22 16:00:50

标签: orientation uilabel

我试图在横向方向上更改UIlabels坐标,所以我这样做了。问题是它不起作用。我做错了什么?

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

1 个答案:

答案 0 :(得分: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 case 除了两种横向模式中的一种。