2011-11-07 52 views
0

我有一個在另一個uiview。我在我的子視圖上有一個按鈕(我已將我的子視圖與我創建的iboutlet uiview連接起來),當我點擊它時,我想要一個新視圖在其位置可見。我使用這段代碼,但當我點擊它時,我看到白色的空白!在另一個uview查看器內的UIview與新的

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:mysubview cache:YES]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1.view cache:YES]; 
[UIView setAnimationDuration: 1.5]; 
[UIView commitAnimations]; 

mysubview.hidden = YES; 
newview1.view.hidden = NO; 

任何幫助表示讚賞!

回答

0

我得到了很多小時後!

下面是代碼:

//獲取currentview

的UIView * currentView = mysubview;

// hide the previous view 
[currentView setHidden:TRUE]; 

//初始化下一視圖

MyMessages *view1=[[MyMessages alloc] initWithNibName:@"MyMessages" bundle:nil]; 

[currentView addSubview:view1.view];//add next view to current 
[currentView setHidden:FALSE];//show current (actually it should be the next view because we added as a subview) 
// set up an animation for the transition between the views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight];//show up the new view from right side (this type of effect happens in navigationcontrollers) 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
// 
[[currentView layer] addAnimation:animation forKey:@"SwitchToView1"]; 
0

父視圖應該能夠使用轉出它的子視圖:

transitionFromView:toView:duration:options:completion: 

使用給定參數指定的視圖之間的過渡動​​畫。

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:  (NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion 

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/clm/UIView/transitionFromView:toView:duration:options:completion

+0

什麼也沒有發生! [UIView的transitionFromView:mysubview toView:view1.view 持續時間:0.5 選項:UIViewAnimationOptionTransitionFlipFromLeft 完成:^(BOOL完成){ /*做某事上動畫完成*/ }]; – stefanosn

+0

你確定你正在動畫的視圖是有效的嗎?他們是否爲零?你如何創建和實例化這些視圖? UINib? – bryanmac

+0

我使用xcode的uiviewcontroller創建了一個項目。然後我從界面生成器中添加了一個新的uiview在我的項目中。我將子視圖連接到我在代碼中創建的iboutlet uiview *子視圖。我綜合它。然後我在我的項目mysdview = [[UIView alloc] init]的viewdidload中像這樣初始化子視圖;我想替換的一個我在另一個轉換中使用它,它的工作原理,但我認爲我的子視圖有問題,但我不知道它是什麼!根據我對子視圖所說的話,這聽起來是否正確? – stefanosn