2011-11-01 2 views
0

이 코드를 사용하여 ios sdk에서 하나의보기에서 다른보기로 전환 할 수 있지만 코드가 트리거되었지만 이전보기로 돌아갈 때 처음으로 작동합니다.CATransition의 코드는 처음에만 작동합니까?

UIView * currentView = self.viewController1.view;

// get the the underlying UIWindow, or the view containing the current view view 
UIView *theWindow = [currentView superview]; 

// remove the current view and replace with myView1 
[currentView setHidden:TRUE];//hide previous view diladi to tabviewcontroller 
self.viewController1=[[MyFriendProfile alloc] initWithNibName:@"MyFriendProfile" bundle:nil]; 
[theWindow addSubview:self.viewController1.view]; 
[currentView setHidden:FALSE]; 
// set up an animation for the transition between the views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView2"]; 

아무 도움 주셔서 감사합니다!

내가 여기에 답이 코드 발견
+0

방금 ​​샘플을 시험 해본 결과 저에게 맞습니다. 내가 한 유일한 일은 뷰 숨기기를 사용하지 않고 addSubview : 메서드를 사용하고 removeFromSuperview 메서드를 호출하는 것을 잊지 마십시오. 두 번째 뷰에서 첫 번째 뷰로 돌아갈 때입니다. – Denis

답변

1

...

// viewcontroller1보기를 얻을

의 UIView * currentView = self.viewController1.view;

// get the the underlying UIWindow, or the view containing the current view view 
UIView *theWindow = [currentView superview]; 

// remove the current view and replace with myView1 
[currentView setHidden:TRUE];//hide previous view diladi to tabviewcontroller 


MyFriendProfile *test1=[[MyFriendProfile alloc] initWithNibName:@"MyFriendProfile" bundle:nil]; 


[theWindow addSubview:test1.view]; 


// set up an animation for the transition between the views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; 
관련 문제