[英]iPhone subView animation: slide down
我已经搜索了一段时间,但是我想要的基本上是“ presentModalViewController”动画,但是反过来...我希望屏幕的顶部落到底部以显示页面。 有人知道那叫什么吗?
这是我到目前为止的代码,但是发生得太快了……我如何减慢速度?
-(void)gotToCreateGameViewController{
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:@"CreateNewGameViewController" bundle:nil];
self.createNewGameViewController = newGame;
createNewGameViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:newGame animated:YES];
[self.view insertSubview:newGame.view atIndex:0];
[newGame release];
我认为您在寻找:UIModalTransitionStyleCoverVertical
Presentation Transition Styles
Transition styles available when presenting view controllers.
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
它从下到上呈现,然后在解雇时从上到下呈现。 要从上到下过渡,您需要自己滚动,或从下面的目标vc开始并以模态显示启动vc。
试试这个代码
-(void)gotToCreateGameViewController{
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:@"CreateNewGameViewController" bundle:nil];
self.createNewGameViewController = newGame;
CATransition *transition = [CATransition animation];
transition.duration = 0.05;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionMoveIn;
CATransition *transition = [CATransition animation];
transition.duration = 0.05;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionMoveIn;
transition.subtype =kCATransitionFromTop;
transition.delegate = self;
transition.subtype =kCATransitionFromTop;
transition.delegate = self;
[self presentModalViewController:newGame animated:NO];
[self.view insertSubview:newGame.view atIndex:0];
[self.view.layer addAnimation:transition forKey:nil];
[newGame release];
请注意,UIModalTransitionStyle仅适用于iPad应用程序。 请参阅文档。
我骇人听闻的答案:
如果将初始视图下移到y = 960(您可能必须添加另一个视图,然后将所有内容剪切并粘贴到该视图中),然后将第二个视图置于y = 0,则可以实现以下代码。 实例化BOOL之后(我称为mine movedUp
):
-(void)moveView:(float)d{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:d];
CGRect rect = self.view.frame;
if (!movedUp)
{
rect.origin.y -= 960;
rect.size.height += 960;
}
else
{
// revert back to the normal state.
rect.origin.y += 960;
rect.size.height -= 960;
}
self.view.frame = rect;
[UIView commitAnimations];
movedUp = !movedUp;
}
- (void)viewDidAppear:(BOOL)animated
{
[self moveView:0.0];
[super viewDidAppear:animated];
}
然后,我将两个按钮(每个视图一个)连接到以下按钮:
-(IBAction)setViewMovedUp:(id)sender
{
[self moveView:0.5];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.