下面是我在做什麼的例子:
在調用視圖控制器我用下面的代碼來切換視圖:
-(void)selectProfile:(User*)selectedUser{
SelectGameViewController* selectGame=[[SelectGameViewController alloc]initWithNibName:@"SelectGame" bundle:nil];
UIView* parent=self.view.superview;
[UIView beginAnimations:@"Show selection" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.50f];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:parent cache:YES];
[selectGame viewWillAppear:YES];
[self viewWillDisappear:YES];
[parent insertSubview:selectGame.view atIndex:0];
[self.view removeFromSuperview];
[selectGame viewDidAppear:YES];
[self viewDidDisappear:YES];
[UIView commitAnimations];
}
然後在出現的觀點,我有以下的代碼該-viewWillAppear方法:
-(void)viewWillAppear:(BOOL)animated{
UIButton* newButton=[[UIButton alloc]initWithFrame:CGRectMake(50, 150, 500, 150)];
[newButton setTitle:@"Play" forState:UIControlStateNormal];
[newButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[newButton.titleLabel setFont:[UIFont fontWithName:@"EraserDust" size:80]];
[newButton addTarget:self action:@selector(playGame:) forControlEvents:UIControlEventTouchUpInside];
newButton.transform = CGAffineTransformMakeRotation(-.2);
[self.view addSubview:newButton];
[newButton release];
[super viewWillAppear:animated];
}
這樣做的結果是,認爲出現與不旋轉的按鈕,但後來它的顯示後立即轉動。我很困惑,因爲這似乎與TechZen的建議不一致?
謝謝 - 我也注意到,如果我以編程方式添加(例如)一個UIButton,然後在-ViewDidLoad中應用一個轉換(稍微旋轉按鈕),該按鈕會立即出現未轉換,然後在已經顯示之後進行轉換。我現在不在我的辦公桌上,但是當我接觸到它時,我會發表一個我的意思的例子。 – 2010-06-07 21:25:09
我已經改變了很多控件,我從來沒有見過。你想確保你把變換放在正確的地方,比如'viewWillAppear'而不是'viewDidAppear'。 – TechZen 2010-06-07 21:36:19
對不起,最後只是一個通用的例子。將變換放在viewDidLoad中應該可以工作。 – TechZen 2010-06-07 21:37:59