我想要一个UIViewController,右边出现一个“幻灯片”动画.不像Push segue,不像Facebook应用程序.我希望新的ViewController在当前的一个上滑动(不要将它推开),但只覆盖屏幕的PART,而另一部分则显示第一个ViewController.
我尝试过的:我最接近的是创建一个具有以下内容的自定义segue:
- (void)perform { __block UIViewController *src = (UIViewController *) self.sourceViewController; __block UIViewController *dst = (UIViewController *) self.destinationViewController; CATransition* transition = [CATransition animation]; transition.duration = .50; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaSEOut]; transition.type = kCATransitionMoveIn; transition.subtype = kCATransitionFromRight; [src.navigationController.view.layer addAnimation:transition forKey:@"SwitchToView1"]; [src.navigationController pushViewController:dst animated:NO]; }
这实现了我想要的动画,但它涵盖了整个第一个ViewController.我怎么能让它停在某一点而不是覆盖整个东西?
我正在使用Storyboards,这是我第一次尝试任何类型的新动画.
解决方法
您可以尝试在源视图控制器中执行此操作,并更改destnation(x轴)的框架,例如:
- (void) perform { UIViewController *dst = (UIViewController *) self.destinationViewController; [dst.view setFrame:CGRectMake(160,YOUR_DST_WIDTH,YOUR_DST_HEIGHT)]; //your animation stuff... [self addChildViewController:dst]; [self.view addSubview:dst.view]; [dst didMoveToParentViewController:self]; }
这应该做到!
如果没有,请告诉我……
UPDATE !:
@CaptJak嘿,对不起,没有为你工作..我写了下面的代码,它在这里没有任何问题..我把它链接到按钮点击..尝试它让我知道! (PS:我也添加了动画!).
ViewController *tlc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; [tlc.view setFrame:CGRectMake(-320,self.view.frame.size.width,self.view.frame.size.height)]; [self addChildViewController:tlc]; [self.view addSubview:tlc.view]; [tlc didMoveToParentViewController:self]; [UIView animateWithDuration:0.3 animations:^{ [tlc.view setFrame:CGRectMake(-160,self.view.frame.size.height)]; }];