使用kCATransitionPush向上滑动UIView

时间:2011-08-31 12:15:45

标签: iphone uiview core-animation uiviewanimationtransition catransition

我试图让UIView向上滑动四分之一的页面以显示其下方的另一个视图(显示选项),然后向下滑动以覆盖这些选项。我无情地搜索过,但似乎无法找到我正在寻找的东西。我不想使用模态视图,因为我想在屏幕上保持顶视图。在下面的代码中,我有点工作,顶层向上滑动,但随后完全消失(淡出)。

非常感谢任何帮助!

感谢。

HomeOptionsViewController *homeOptionsViewController  = [[HomeOptionsViewController  alloc] 
                      initWithNibName:@"HomeOptionsViewController" 
                      bundle:nil];
// get the view that's currently showing
UIView *currentView = self.view;
// get the the underlying UIWindow, or the view containing the current view
UIView *theWindow = [currentView superview];

UIView *newView = homeOptionsViewController.view; 
//newView.frame = CGRectMake(0,300, 320,140);
    newView.frame = CGRectMake(0,-10, 320,140);
// remove the current view and replace with myView1
//---[currentView removeFromSuperview];
[theWindow addSubview:newView];

theWindow.frame = CGRectMake(0,-110,320,200);

newView.frame = theWindow.bounds;
// set up an animation for the transition between the views

CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//[theWindow setFrame:CGRectMake(0,200,320,300)];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];

1 个答案:

答案 0 :(得分:3)

您没有使用标准UIView动画的任何原因? CATransitions将完全改变视图,因为它应该是从一个视图到另一个视图的转换。

你尝试过这样的事吗?您可以添加要从屏幕底部滑动的视图,然后为两个帧更改动画。它会产生一个上滑效果。

newView.frame = CGRectMake(0,416,320,140);
[theWindow addSubview:newView];
[UIView beginAnimations:@"SwitchToView1" context:nil];
[UIView setAnimationDuration:0.5];
theWindow.frame = CGRectOffset(theWindow.frame, 0, -140);
newView.frame = CGRectOffset(newView.frame, 0, -140);
[UIView commitAnimations];