2011-12-20 2 views
0

webview 및 UIToolbar가있는보기가 있습니다.하나의 UIView를 제거하고 다른 UIView를 추가하여 슬라이드 애니메이션을 만듭니다.

"kCATransitionFromTop"전환을 수행하는 애니메이션을 만들려면 먼저 이전 웹보기를 제거한 다음 새 webView를 superView에 추가하십시오. 이 전환 중에 툴바가 현재 위치에 상관없이 움직이지 않고 움직이지 않기를 바란다.

코드 :

toolbar = [[UIToolbar alloc] init]; 
toolbar.barStyle = UIBarStyleDefault; 
toolbar.tintColor = [UIColor blackColor]; 
[toolbar setFrame:CGRectMake(0, 480 - 88 - 20, 320.0, 44)]; 
//Add the toolbar as a subview to the navigation controller. 
[self.view addSubview:toolbar]; 

는 애니메이션 도구 모음 추가

UIView *currentView = webView; 
UIView *theWindow = [currentView superview]; 

UIView *newView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 320, self.view.bounds.size.height - self.navigationController.toolbar.frame.size.height)]; 
newView.backgroundColor = [UIColor whiteColor]; 

// remove the current view and replace with new view 
[currentView removeFromSuperview]; 
[theWindow insertSubview:newView belowSubview:toolbar]; 

// set up the animation 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.4]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromTop]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

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

모든 도구 모음을 제외하고, 확인 밖으로 작동하는 것 같다뿐만 아니라 웹보기로 이동 ... 내가 무엇을했는지 잘못하고 어떻게이 문제를 해결할 수 있습니까?

답변

0

layer의 전환을 newView에만 적용 하시겠습니까?

[[newView layer] addAnimation:animation forKey:@"PushNextArticleView"]; 
+0

감사합니다. 문제가 해결되었습니다. 그러나 전환 사이에는 블랙홀이 있습니다. removeFromSuperview가 움직이지 않는다고 생각합니까? – user959974

+0

수정. 자신을 레이어의 위임자로 설정하고'-animationDidStop : finished :'을 구현하십시오. 애니메이션이 중지되면이 메시지가 전달되고 슈퍼 뷰에서 원래 뷰를 제거 할 수 있습니다. –

+0

[currentView removeFromSuperview]를 주석 처리 할 때; , 어떻게 든 그 견해는 지금 애니메이션을 수행하는 것을 거절합니다. 그들은 insertSubview 메서드를 사용하지 않는 것 같습니다. 내가 AddSubview에 말하면, 애니메이션은 괜찮을 것입니다 ..... – user959974

관련 문제