如何在超级视图更改大小时告诉子视图调整大小?

时间:2016-04-27 22:54:28

标签: ios swift uiviewcontroller mapkit mkmapviewdelegate

我正在开发一个iOS应用程序,它有一个UIViewController,其视图有一个MapView作为子视图。但是,当我运行应用程序并尝试在模拟器中旋转视图时,它并没有按预期工作;它留下了一个黑盒子,如图所示:

Original View

Rotated View

如何告诉MapView调整其超级视图?

1 个答案:

答案 0 :(得分:1)

尝试使用此代码

<强> ObjC

unit MyPanel;

interface

uses
  System.SysUtils, System.Classes, Vcl.Controls, Vcl.ExtCtrls;

type
  TMyPanel = class(TPanel)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MyComponents', [TMyPanel]);
end;

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;
end;

destructor TMyPanel.Destroy;
begin
  inherited;
end;

end.

Swift

yourMapView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
                               UIViewAutoresizingFlexibleLeftMargin |
                               UIViewAutoresizingFlexibleBottomMargin;