6

UIViewController's内側にあるビューの高さを変更して、UINavigationController何も見えないように下部にバナーを表示したいと思います。

ビューのフレームを変更するだけでこれはかなり簡単だと思いましたviewDidLoadが、うまくいきませんでした。

CGRect frame = self.view.frame;
self.view.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - 49.0f);

私も追加しようとしました

[navigationController.view setAutoresizesSubviews:NO];

開始した後ですUINavigationControllerが、それでも同じように見えます。

私が今考えることができる唯一のオプションは、バナーによって隠されるUINavigationControllerダミーの内側を使用するUITabBarControllerことですが、それは私には不必要に複雑に思えます。

ビューコントローラーのビュー内の高さを変更する方法はありますUINavigationControllerか?

4

2 に答える 2

5

ビューコントローラ内からビューコントローラのビューを変更する方法はありませんが、カスタムコンテナビューコントローラを使用できます。

// Create container
UIViewController* container = [[UIViewController alloc] init];

// Create your view controller
UIViewController* myVc = [[MyViewController alloc] init];

// Add it as a child view controller
[container addChildViewController:myVc];
[container.view addSubview:myVc.view];
myVc.view.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleHeight;
myVc.view.frame = CGRectMake(0, 0, container.view.bounds.size.width, container.view.bounds.size.height-200);

// Add your banner
UIImageView* imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"banner"]];
imgView.autoresizingMask = UIViewAutoresizingMaskFlexibleWidth| UIViewAutoresizingMaskFlexibleTopMargin;
imgView.frame = CGRectMake(0, container.view.bounds.size.height-200, container.view.bounds.size.width, 200);
[myVc.view addSubview:imgView];

containerこれで、ビューコントローラをナビゲーションコントローラの代わりに追加できます。

于 2012-11-05T12:46:52.450 に答える
0

@jjv360のSwift5バージョンの回答:

override func viewDidLoad() {
    super.viewDidLoad()

    let myVc = UIViewController()
    
    self.addChild(myVc)
    self.view.addSubview(myVc.view)
    myVc.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    myVc.view.frame = CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height-200)
        
    let imgView = UIImageView(image: UIImage(named: "banner"))
    imgView.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
    imgView.frame = CGRect(x: 0, y: self.view.bounds.size.height-200, width: 
    self.view.bounds.size.width, height: 200)
        myVc.view.addSubview(imgView)
}
于 2020-10-20T04:38:58.830 に答える