問題: 我有兩個視圖控制器加載到根視圖控制器。兩個子視圖佈局都會響應方向更改。我使用[UIView transformationFromView:...]在兩個視圖之間切換。兩個子視圖的工作對自己好的,但如果...隱藏UIView方向更改/佈局問題
- 意見被交換
- 取向的變化
- 意見再次交換
以前隱藏的視圖有嚴重的佈局問題。我越重複這些步驟,問題越嚴重。
實施細則
我有三個viewsControllers。
- MyAppViewController
- A_ViewController
- B_ViewController
甲&乙ViewControllers各自具有背景圖像,並分別一個UIWebView和AQGridView。爲了給你如何我建立的一切,例如,下面是爲A_ViewController的方法的loadView ...
- (void)loadView {
[super loadView];
// background image
// Should fill the screen and resize on orientation changes
UIImageView *bg = [[UIImageView alloc] initWithFrame:self.view.bounds];
bg.contentMode = UIViewContentModeCenter;
bg.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
bg.image = [UIImage imageNamed:@"fuzzyhalo.png"];
[self.view addSubview:bg];
// frame for webView
// Should have a margin of 34 on all sides and resize on orientation changes
CGRect webFrame = self.view.bounds;
webFrame.origin.x = 34;
webFrame.origin.y = 34;
webFrame.size.width = webFrame.size.width - 68;
webFrame.size.height = webFrame.size.height - 68;
projectView = [[UIWebView alloc] initWithFrame:webFrame];
projectView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:projectView];
}
爲了簡潔起見,在B_ViewController的AQGridView設置幾乎相同的方式。
現在這兩個視圖都可以正常工作。但是,我使用這兩者在這樣的AppViewController ...
- (void)loadView {
[super loadView];
self.view.autoresizesSubviews = YES;
[self setWantsFullScreenLayout:YES];
webView = [[WebProjectViewController alloc] init];
[self.view addSubview:webView.view];
mainMenu = [[GridViewController alloc] init];
[self.view addSubview:mainMenu.view];
activeView = mainMenu;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(switchViews:) name:SWAPVIEWS object:nil];
}
和我切換betweem用我自己的方法SWITCHVIEW這樣
- (void) switchViews:(NSNotification*)aNotification;
{
NSString *type = [aNotification object];
if ([type isEqualToString:MAINMENU]){
[UIView transitionFromView:activeView.view toView:mainMenu.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil];
activeView = mainMenu;
}
if ([type isEqualToString:WEBVIEW]) {
[UIView transitionFromView:activeView.view toView:webView.view duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
activeView = webView;
}
// These don't seem to do anything
//[mainMenu.view setNeedsLayout];
//[webView.view setNeedsLayout];
}
我摸索着我的方式,通過這兩種觀點這個,我懷疑我所做的很多事情都是錯誤地實現的,所以請隨時指出應該以不同方式完成的任何事情,我需要輸入。
但我主要關心的是瞭解導致佈局問題的原因。下面是該說明的佈局問題的性質兩幅圖像...
UPDATE: 我注意到,當方向是橫向,過渡垂直翻轉,當我希望它是水平的。我不知道這是什麼可能出錯的線索。
切換到另一種觀點...改變方向....切換回....