0

UIViewControllerと2つのUIButtonを含むUIViewを作成しました。

self.view = [[UIView alloc]initWithFrame:CGRectMake( 0,0,320,480)];
self.view.autoresizesSubviews = YES;

self.view.backgroundColor = [UIColor redColor];
UIView *view;
view = [[UIVew alloc]initWithFrame:CGRectMake(0,0,320,480)];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIButton *button1;
button.frame = CGRectMake(100,130,120,50);
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
[controller addSubview:view];

// […]

- (void)buttonAction:(id)sender
{
    // I have created another view for a purpose
    [view removeFromSuperview];
    UIView *view_obj;
    view_obj.backgroundColor = [UIColor greenColor];
    view_obj.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth;
    [self.view addSubview:view_obj];  
}

問題:向きを横向きに変更すると、ボタンのあるビューのサイズが変更されますが、ボタンをクリックすると、blueColorのビューが自動サイズ変更されずに表示されます。半分をredColorのルートビューとして、半分をgreenColorのサブビューとして表示できます。また、ShouldAutoRotateメソッドをオーバーライドして、このプロジェクトをプログラムで実行しました。返信してください。

4

2 に答える 2

0

Interface Builder でビュー オブジェクトを選択し、インスペクター ウィンドウの [View Attributes] ペインで、ステータス バーと [Navigation Bar] の [Top Bar] が選択されていることを確認します (アプリにナビゲーション バーがある場合)。これらは、「シミュレートされたユーザー インターフェイス要素」セクションの上部付近に表示されます。これにより、UIViewController のビューのサイズを決定するときに、常にこれらの余地を残すようにアプリに通知します。

于 2010-08-13T14:57:58.397 に答える
-1

この質問を研究してみてください。

または

次のコードを参照してください From this question

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {    
    UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation;
    if (interfaceOrientation == UIInterfaceOrientationPortrait 
        || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        button1.frame = CGRectMake(100, 33, 226, 275);
        button2.frame = CGRectMake(440, 33, 226, 275);
        button3.frame = CGRectMake(100, 360, 226, 275);
        button4.frame = CGRectMake(440, 360, 226, 275);
        button5.frame = CGRectMake(100, 693, 226, 275);
        button6.frame = CGRectMake(440, 693, 226, 275);
    }
    else 
    {
        button1.frame = CGRectMake(100, 50, 226, 275);
        button2.frame = CGRectMake(400, 50, 226, 275);
        button3.frame = CGRectMake(700, 50, 226, 275);
        button4.frame = CGRectMake(100, 400, 226, 275);
        button5.frame = CGRectMake(400, 400, 226, 275);
        button6.frame = CGRectMake(700, 400, 226, 275);
    }
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation || UIInterfaceOrientationPortraitUpsideDown);
}
于 2010-05-21T06:21:46.267 に答える