-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;
}

私はこのコードの正しさをテストしていません。私が言える唯一のことは、2 つのランドスケープ モードのいずれかを 除くすべての場合に、ラベル フレームがその CGRect にリセットされるということです。

于 2012-06-22T16:13:37.637 に答える