iOS - UIView 无法横向调整大小
一些非常奇怪的事情发生在我身上(至少对我来说很奇怪) 我有一个视图控制器(fileManagerViewController),它的 UI 基本上是一个空视图 顶部有一个工具栏。我用 IB 制作了这个 UI。在工具栏上我有一些按钮,其中两个按钮用于在两个视图之间切换。我必须切换的两个视图的 UI 是由代码编写的。
- 在 FileManagerViewController 的 viewDidLoad 中,我写了这
-(void) viewDidLoad {
[super viewDidLoad];
fileManagerTableView = [[FileManagerTableView alloc] init];
fileManagerGridView = [[FileManagerGridView alloc] init];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight
|UIViewAutoresizingFlexibleWidth;
self.view.autoresizesSubviews=YES;
self.view addSubview:fileManagerTableView.view];
[self.view addSubview:fileManagerGridView.view];
[fileManagerTableView.view setHidden:YES];
}
- 两个 loadView 方法,
-(void) loadView {
CGRect fileGridViewFrame = CGRectMake(0.0, 50.0, 1024,768);
fileGridView = [[[AQGridView alloc]
initWithFrame:fileGridViewFrame]
autorelease];
fileGridView.dataSource=self;
fileGridView.delegate=self;
fileGridView.autoresizingMask=UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight
fileGridView.autoresizesSubviews=YES;
fileGridView.bounces;
fileGridView.backgroundColor = [[UIColor colorWithPatternImage:
[UIImage imageNamed:@"bg.png"]]];
[self.fileGridView reloadData];
self.view = fileGridView;
}
-(void) loadView {
CGRect fileTableViewFrame = CGRectMake(0.0, 44.0, 1024,768);
fileGridView = [[[UITableView alloc]
initWithFrame:fileTableViewFrame]
autorelease];
fileGridView.dataSource=self;
fileGridView.delegate=self;
fileGridView.autoresizingMask=UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight
fileGridView.autoresizesSubviews=YES;
fileGridView.bounces;
fileGridView.backgroundColor = [[UIColor colorWithPatternImage:
[UIImage imageNamed:@"bg.png"]]];
[self.fileGridView reloadData];
self.view = fileGridView;
}
结果是,正如我所说,奇怪的是,如果应用程序以纵向模式启动,那么所有的工作都如我所期望的那样,这两个视图在纵向和横向模式下渲染得很好。如果应用程序在设备横向启动时,视图不会填满整个屏幕。看看这个 屏幕截图
something really weird it's happening to me (at least weird for me)
I have a view controller (fileManagerViewController) the UI of this is basically an empty view
with a toolbar on top. I made this UI with IB. on the toolbar i have some buttons, two of those buttons are used to switch between two views. The UI for the two views that I've to switch was made by code.
- Inside the viewDidLoad of FileManagerViewController I wrote this
-(void) viewDidLoad {
[super viewDidLoad];
fileManagerTableView = [[FileManagerTableView alloc] init];
fileManagerGridView = [[FileManagerGridView alloc] init];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight
|UIViewAutoresizingFlexibleWidth;
self.view.autoresizesSubviews=YES;
self.view addSubview:fileManagerTableView.view];
[self.view addSubview:fileManagerGridView.view];
[fileManagerTableView.view setHidden:YES];
}
- those are the two loadView methods
-(void) loadView {
CGRect fileGridViewFrame = CGRectMake(0.0, 50.0, 1024,768);
fileGridView = [[[AQGridView alloc]
initWithFrame:fileGridViewFrame]
autorelease];
fileGridView.dataSource=self;
fileGridView.delegate=self;
fileGridView.autoresizingMask=UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight
fileGridView.autoresizesSubviews=YES;
fileGridView.bounces;
fileGridView.backgroundColor = [[UIColor colorWithPatternImage:
[UIImage imageNamed:@"bg.png"]]];
[self.fileGridView reloadData];
self.view = fileGridView;
}
-(void) loadView {
CGRect fileTableViewFrame = CGRectMake(0.0, 44.0, 1024,768);
fileGridView = [[[UITableView alloc]
initWithFrame:fileTableViewFrame]
autorelease];
fileGridView.dataSource=self;
fileGridView.delegate=self;
fileGridView.autoresizingMask=UIViewAutoresizingFlexibleWidth|
UIViewAutoresizingFlexibleHeight
fileGridView.autoresizesSubviews=YES;
fileGridView.bounces;
fileGridView.backgroundColor = [[UIColor colorWithPatternImage:
[UIImage imageNamed:@"bg.png"]]];
[self.fileGridView reloadData];
self.view = fileGridView;
}
the result is, as i said weird, if the app start in portrait mode all works as I expect the two view s are rendered well in portrait and landscape mode. If the app is started with the device in landscape orientation the views don't fill the entire screen. Have a look a this
screenshot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 IB 内部的布局控件中,使用调整大小控件。要访问上述控件,请打开检查器中的第三个选项卡 (Cmd+3)
另外,在 viewWillAppear 方法内部,在视图上调用 setNeedsDisplay。
Inside of IB, in the layout controls, play with the resize controls. To access the said controls, open the third tab in inspector (Cmd+3)
Also, inside of your viewWillAppear method, call setNeedsDisplay on your view.