iphone - 使用 kCATransitionPush 向上滑动 UIView

标签 iphone uiview core-animation uiviewanimationtransition catransition

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

非常感谢任何帮助!

谢谢。

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"];

最佳答案

您不使用标准 UIView 动画的原因是什么? CATransitions 将完全改变 View ,因为它应该是从一个 View 到另一个 View 的转换。

你尝试过这样的事情吗?您添加要从屏幕底部滑动的 View ,然后为两个帧的变化设置动画。它创建了向上滑动的效果。

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];

关于iphone - 使用 kCATransitionPush 向上滑动 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7256788/

相关文章:

ios - 核心动画图像序列

objective-c - 尝试制作圆角 UIImage 时的性能问题(使用 mask )

iphone - ios UITableView删除/重新排列编辑模式但不显示删除图标

ios - UIView 仅在一个 View Controller 中设置动画

ios - 如何将触摸事件发送到 iOS 上的 UIView

ios - 修改viewWithTag

ios - 动画 UIView 形状及其内容

iphone - 带有文本和图像的 UITableView : mixed up in dequeueReusableCellWithIdentifier

ios - 在 Swift 中根据条件使用调度队列的最佳方法

iphone - 如何在 iPhone 中调整 UINavigationController 的大小?